Having had occasion to compile pycrypto 2.3.1 for Win7-64 and Python 2.7.1-64, I’ll share the process, and the result.
Note 2016-02-03: This post is seriously old at this point, and pycrypto is not being actively maintained. Use pycryptodome, a fork of pycrypto, instead. It installs easily on Windows, pre-compiled or compiled from source, with good documentation on how to install it.
Compiling pycrypto on Win7-64 is very straightforward, unless you happen to use Visual Studio Express, not Visual Studio Pro. Compiling with Express takes a couple extra steps, which is what this post is about.
Preparing to compile:
- Install VC++ 2008 SP1 Express. Needs to be 2008, not 2010 – that goes back to an old tradition that modules need to be compiled with the version that Python was compiled with, which happens to be 2008 right now. The Express version of VC++ 2008 is still available: http://www.microsoft.com/express/Downloads/#2008-Visual-CPP. If you are nervous about whether it will remain available, download the ISO.
- You now also need the Windows SDK so you have the amd64 compiler, which isn’t included in the Express version. This needs to be the Win7 + Net 3.5 SDK, not the Win7 + Net 4.0 SDK. You can find it here: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c17ba869-9671-4330-a63e-1fd44e0e2505&displaylang=en , and again download the ISO (the one for amd64 support though!) if nervous it may disappear. Install and make sure you install the “Visual C++ Compilers”.
Python 2.7.1 has a bug where it will get confused withthe paths that MS use for Express , whichhappen to be different than the paths used in Pro, which breaks vcvarsall.bat when attempting to build 64-bit binaries. This is a limitation of VC++ 2008 Express. The Python distutils team offers a work-around. Check the bug at http://bugs.python.org/issue7511 to see whether the issue has been resolved already in your version of Python. If not so, grab the diff attached to that bug report and apply it to your Python main directory using “patch”. The command line for this is “patch -p0 <vcvars4.diff”.
If you don’t have a copy of “patch” already, the Cygwin default install + patch (not patchutils) will give you patch.
Now you’re ready to compile. This is pretty simple from here on out:
- pycrypto should be unpacked somewhere other than your Python dir, say c:\temp
- Then, from within the pycrypto directory, run these commands:
- python setup.py build -c msvc
- python setup.py install
- python setup.py test
In my case, Python 3.1 is actually my registered default version, and I have python 2.7 renamed as python27.exe and pythonw27.exe. The build and install still works fine using python27 to invoke instead of python. Both my Python dirs are in the %path% to make my life easier. No PYTHON* env variables have been set.