I’ve read every other google source and SO thread, with nothing working.
Python 2.7.3 32bit installed on Windows 7 64bit. Download, extracting, and then trying to install PyCrypto results in "Unable to find vcvarsall.bat".
So I install MinGW and tack that on the install line as the compiler of choice. But then I get the error "RuntimeError: chmod error".
How in the world do I get around this? I’ve tried using pip, which gives the same result. I found a prebuilt PyCrypto 2.3 binary and installed that, but it’s nowhere to be found on the system (not working).
Any ideas?
回答 0
如果尚未安装与Python.org分发的Visual Studio二进制文件兼容的C / C ++开发环境,则应坚持仅安装纯Python软件包或可用于Windows二进制文件的软件包。
If you don’t already have a C/C++ development environment installed that is compatible with the Visual Studio binaries distributed by Python.org, then you should stick to installing only pure Python packages or packages for which a Windows binary is available.
Microsoft has recently recently released a standalone, dedicated Microsoft Visual C++ Compiler for Python 2.7. If you’re using Python 2.7, simply install that compiler and Setuptools 6.0 or later, and most packages with C extensions will now compile readily.
After years and years, python finally agreed for a binary disribution called wheel which allows to install even binary extensions on Windows without having a compiler with simple pip install packagename. There is a list of popular packages with their status. Pycrypto is not there yet, but lxml, PySide and Scrapy for example.
Edited Nov 2015: pip uninstall pycrypto & pip install pycryptodome. It is a pycrypto fork with new features and it supports wheel. It replaces pycrypto, so existing code will continue to work (see https://pycryptodome.readthedocs.org/en/latest/src/examples.html)
vcvarsall.bat is part of the Visual C++ compiler, you need that to install what you are trying to install. Don’t even try to deal with MingGW if your Python was compiled with Visual Studio toolchain and vice versa. Even the version of the Microsoft tool chain is important. Python compiled with VS 2008 won’t work with extensions compiled with VS 2010!
Beware using Visual Studio 2010 or not using Visual Studio 2008
As far as I know the following is still true. This was posted in the link above in June, 2010 referring to trying to build extensions with VS 2010 Express against the Python installers available on python.org.
Be careful if you do this. Python 2.6 and 2.7 from python.org are
built with Visual Studio 2008 compilers. You will need to link with
the same CRT (msvcr90.dll) as Python.
Visual Studio 2010 Express links with the wrong CRT version:
msvcr100.dll.
If you do this, you must also re-build Python with Visual Studio 2010
Express. You cannot use the standard Python binary installer for
Windows. Nor can you use any C/C++ extensions built with a different
compiler than Visual Studio 2010 (Express).
Opinion: This is one reason I abandoned Windows for all serious development work for OSX!
I have managed to get pycrypto to compile by using MinGW32 and MSYS. This presumes that you have pip or easy_install installed.
Here’s how I did it:
1) Install MinGW32. For the sake of this explanation, let’s assume it’s installed in C:\MinGW. When using the installer, which I recommend, select the C++ compiler. MSYS should install with MinGW
2) Add c:\mingw\bin,c:\mingw\mingw32\bin,C:\MinGW\msys\1.0, c:\mingw\msys\1.0\bin and c:\mingw\msys\1.0\sbin to your %PATH%. If you aren’t familiar, this article is very helpful.
3) From the search bar, run msys and the MSYS terminal will open. For those familiar with Cygwin, it works in a similar fashion.
4) From within the MSYS terminal pip install pycrypto should run without error after this.
It’s possible to build PyCrypto using the Windows 7 SDK toolkits. There are two versions of the Windows 7 SDK. The original version (for .Net 3.5) includes the VS 2008 command-line compilers. Both 32- and 64-bit compilers can be installed.
The first step is to compile mpir to provide fast arithmetic. I’ve documented the process I use in the gmpy library. Detailed instructions for building mpir using the SDK compiler can be found at sdk_build
The key steps to use the SDK compilers from a DOS prompt are:
1) Run either vcvars32.bat or vcvars64.bat as appropriate.
2) At the prompt, execute “set MSSdk=1”
3) At the prompt, execute “set DISTUTILS_USE_SDK=1”
This should allow “python setup.py install” to succeed assuming there are no other issues with the C code. But I vaaguely remember that I had to edit a couple of PyCrypto files to enable mpir and to find the mpir libraries but I don’t have my Windows system up at the moment. It will be a couple of days before I’ll have time to recreate the steps. If you haven’t reported success by then, I’ll post the PyCrypto steps. The steps will assume you were able to compile mpir.
打开Windows提升的命令提示符cmd.exe(带有“以管理员身份运行”),为所有用户安装“适用于Python 2.7的Microsoft Visual C ++编译器”。您可以使用以下命令来执行此操作:msiexec / i C:\users\jozko\download\VCForPython27.msi ALLUSERS=1仅使用您自己的文件路径:msiexec /i <path to MSI> ALLUSERS=1
Install setuptools (setuptools 6.0 or later is required for Python to automatically detect this compiler package)
either by:pip install setuptoolsor download “Setuptools bootstrapping installer” source from, save this file somwhere on your filestystem as “ez_python.py” and install with: python ez_python.py
Install wheel (wheel is recommended for producing pre-built binary packages). You can install it with: pip install wheel
Open Windows elevated Command Prompt cmd.exe (with “Run as administrator”) to install “Microsoft Visual C++ Compiler for Python 2.7” for all users. You can use following command to do so: msiexec /i C:\users\jozko\download\VCForPython27.msi ALLUSERS=1 just use your own path to file: msiexec /i <path to MSI> ALLUSERS=1
Now you should be able to install pycrypto with: pip install pycrypto
If you are on Windows and struggling with installing Pycrypcto just use the:
pip install pycryptodome.
It works like a miracle and it will make your life much easier than trying to do a lot of configurations and tweaks.
回答 14
这可能不是最佳解决方案,但是您可以从MS下载并安装免费的Visual C ++ Express软件包。这将为您提供编译PyCrypto代码所需的C ++编译器。
This probably isn’t the optimal solution but you might download and install the free Visual C++ Express package from MS. This will give you the C++ compiler you need to compile the PyCrypto code.
My answer might not be related to problem mention here, but I had same problem with Python 3.4 where Crypto.Cipher wasn’t a valid import. So I tried installing PyCrypto and went into problems.
After some research I found with 3.4 you should use pycryptodome.
I install pycryptodome using pycharm and I was good.
Due to weird legal reasons, binaries are not published the normal way. Voidspace is normally the best second source. But since quite some time, voidspace maintainer did not update.
Use the zip from [https://www.dropbox.com/s/n6rckn0k6u4nqke/pycrypto-2.6.1.zip?dl=0]
步骤6a:通过将目录更改为C:\ Program Files(x86)\ Microsoft Visual Studio版本\ VC \在C:\ Program Files(x86)\ Microsoft Visual Studio 10.0 \ VC \ bin \ amd64中创建vcvars64.bat文件命令提示符。在命令提示符下键入命令:
cd C:\Program Files (x86)\Microsoft Visual Studio version\VC\r
Step 1: Install Visual C++ 2010 Express from
here.
(Do not install Microsoft Visual Studio 2010 Service Pack 1 )
Step 2: Remove all the Microsoft Visual C++ 2010 Redistributable packages from Control Panel\Programs and Features. If you don’t do those then the install is going to fail with an obscure “Fatal error during installation” error.
Step 3: Install offline version of Windows SDK for Visual Studio 2010 (v7.1) from here.
This is required for 64bit extensions. Windows has builtin mounting for ISOs like Pismo.
Step 4: You need to install the ISO file with Pismo File Mount Audit Package. Download Pismo from here
Step 5: Right click the downloaded ISO file and choose mount with Pismo. Thereafter, install the Setup\SDKSetup.exe instead of setup.exe.
Step 6a: Create a vcvars64.bat file in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64 by changing directory to C:\Program Files (x86)\Microsoft Visual Studio version\VC\ on the command prompt.
Type command on the command prompt:
cd C:\Program Files (x86)\Microsoft Visual Studio version\VC\r
Step 6b:
To configure this Command Prompt window for 64-bit command-line builds that target x86 platforms, at the command prompt, enter:
vcvarsall x86 Click here for more options.
Step 7: At the command prompt, install the PyCrypto by typing:
C:\Python3X>pip install -U your_wh_file
Go to pycharm -> file -> setting -> project interpreter
Click on +
Search for "pycrypto" and install the package
Note: If you don’t have “Microsoft Visual C++ Compiler for Python 2.7” installed then it will prompt for installation, once installation finished try the above steps it should work fine.