Installation¶
The installation procedure depends on the package you want the library to be in. PyCryptodome can be used as:
-
An almost drop-in replacement for the old PyCrypto library. You install it with:
In this case, all modules are installed under the Crypto package. You can test everything is right with:
You can test everything is right with:
If you intend to run PyCryptodome with Python 2.7 under Windows, you must first install the Microsoft Visual C++ 2015 Redistributable. That is not necessary if you use Python 3.
The procedures below go a bit more in detail, by explaining how to setup the environment for compiling the C extensions for each OS, and how to install the GMP library.
Compiling in Linux Ubuntu¶
If you want to install under the Crypto package, replace below pycryptodomex with pycryptodome .
Compiling in Linux Fedora¶
If you want to install under the Crypto package, replace below pycryptodomex with pycryptodome .
Windows (from sources)¶
If you want to install under the Crypto package, replace below pycryptodomex with pycryptodome .
Windows does not come with a C compiler like most Unix systems. The simplest way to compile the PyCryptodome extensions from source code is to install the minimum set of Visual Studio components freely made available by Microsoft.
[Once only] Download Build Tools for Visual Studio 2019. In the installer, select the C++ build tools, the Windows 10 SDK, and the latest version of MSVC v142 x64/x86 build tools.
Compile and install PyCryptodome:
To make sure everything work fine, run the test suite:
Documentation¶
Project documentation is written in reStructuredText and it is stored under Doc/src . To publish it as HTML files, you need to install sphinx and use:
It will then be available under Doc/_build/html/ .
PGP verification¶
All source packages and wheels on PyPI are cryptographically signed. They can be verified with the following PGP key:
Python 3 — Install pycrypto on Windows
I'm using Python 3.7 and Windows 10. 'pip install pycrypto' doesn't work with the following error:
The file include\pyport.h in Python installation directory does not have #include < stdint.h > anymore. This leaves intmax_t undefined.
A workaround for Microsoft VC compiler is to force include stdint.h via OS environment variable CL:
- Open command prompt, and Setup VC environment by runing vcvars*.bat (choose file name depending on VC version and architecture)
- set CL=-FI"Full-Path\stdint.h" (use real value for Full-Path for the environment)
- then, try to install pycrypto again:
Another option that I'll try in future is to use PyCryptodome instead of pycrypto. pycrypto is discontinued and is no longer actively supported. PyCryptodome exposes almost the same API as pycrypto (source).
Как установить PyCrypto в Windows?
Я читал каждый другой источник google и поток SO, ничего не работая.
Python 2.7.3 32bit установлен на Windows 7 64bit . Загрузите, извлеките, а затем попытайтесь установить результаты PyCrypto в «Unable to find vcvarsall.bat».
Итак, я устанавливаю MinGW и придерживаюсь того, что на установочной линии является компилятором. Но затем я получаю сообщение об ошибке «RuntimeError: chmod error».
Как я могу обойти это в мире? Я пробовал использовать pip, который дает тот же результат. Я нашел предустановленный двоичный файл PyCrypto 2.3 и установил его, но его нигде не найти в системе (не работает).
17 ответов
Если у вас еще нет установленной среды разработки C/С++, совместимой с бинарниками Visual Studio, распространяемыми Python.org, вам следует придерживаться установки только чистых пакетов или пакетов Python, для которых доступен двоичный файл Windows.
К счастью, для Windows имеются доступные двоичные файлы PyCrypto: http://www.voidspace.org.uk/python/modules.shtml#pycrypto
UPDATE:
Как поясняет @Udi в комментарии ниже, следующая команда также устанавливает pycrypto и также может использоваться в virtualenv :
Обратите внимание, чтобы выбрать соответствующую ссылку для вашей установки из этот список
Если вы ищете сборки для Python 3.5, см. PyCrypto на python 3.5
Недавно Microsoft недавно выпустила автономный, выделенный Microsoft Visual С++ Compiler для Python 2.7. Если вы используете Python 2.7, просто установите этот компилятор и Setuptools 6.0 или более поздней версии, и большинство пакетов с расширениями C теперь будут легко компилироваться.
Обычно
vcvarsall.bat является частью компилятора Visual С++, вам необходимо установить то, что вы пытаетесь установить. Даже не пытайтесь иметь дело с MingGW, если ваш Python был скомпилирован с помощью инструментальной цепочки Visual Studio и наоборот. Даже важна версия цепочки инструментов Microsoft. Python, скомпилированный с VS 2008, не будет работать с расширениями, скомпилированными с VS 2010!
Вы должны скомпилировать PyCrypto с тем же компилятором, с которым была скомпилирована версия Python. Google для «Не удалось найти vcvarsall.bat», потому что это корень вашей проблемы, Это очень распространенная проблема с компиляцией расширений Python в Windows.
Остерегайтесь использования Visual Studio 2010 или не используете Visual Studio 2008
Насколько я знаю, все еще верно. Это было опубликовано в ссылке выше в июне 2010 года, ссылаясь на попытку создания расширений с помощью VS 2010 Express в отношении установщиков Python, доступных на python.org.
Будьте осторожны, если вы это сделаете. Python 2.6 и 2.7 из python.org — это построенный с помощью компиляторов Visual Studio 2008. Вам нужно будет установить связь с тот же CRT (msvcr90.dll) как Python.
Ссылки на Visual Studio 2010 Express с неправильной версией CRT: msvcr100.dll.
Если вы это сделаете, вы также должны перестроить Python с помощью Visual Studio 2010 Экспресс. Вы не можете использовать стандартный двоичный установщик Python для Окна. Вы также не можете использовать любые расширения C/С++, созданные с помощью другого компилятор, чем Visual Studio 2010 (Express).
Мнение: Это одна из причин, по которой я отказался от Windows для всех серьезных разработок OSX!