Compiling pycrypto on Win7-64

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.

TLDR first: Here’s an archive of the compiled pycrpyto library. It was built with VC++ 2008 SP1, and assumes you are using the x86-64 version of Python 2.7.x. Unpack this archive into your Python main directory. It’ll end up in Lib/site-packages/Crypto.

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.
  • Python 2.7.1 has a bug where it will get confused with the paths that MS use for Express, which happen 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.

About these ads

15 Responses to Compiling pycrypto on Win7-64

  1. Jason says:

    Thanks! I was looking all over for this and was afraid that I would have to figure out how to compile it myself.

  2. Robbie says:

    Following your steps PyCrypto installed perfectly. Thanks for this really useful advice!

  3. Zuse says:

    You saved hours of my life! Thanks!

  4. $p00ky says:

    Works perfectly!
    It took me so long to find the solution… You should ask PyCrypto to add a link to your post ;)
    Thanks a lot.

  5. David says:

    Hello I was looking for the pcCrypto 64-bit. Founding yur page gave me a lot of hope, but seems the link to the actually complied library is dead.
    Would it possible to reupload the lib, please? :)

  6. Jelena says:

    Thank you, the compiled library helped me a lot!

  7. gchrome says:

    Hi, thanks for your work! I unpacked the library, but it gave me an error – DLL load failed: %1 is not a valid Win32 application.
    Maybe I am missing some steps?

  8. supergq says:

    Alternatively, simply download and install ActivePython, then run…

    pypm install pycrypto

  9. avraham says:

    I believe it is worth mentioning the path I took
    Installed the prerequisites, (VC++ 2008 SP1 Express and WinSDK)
    used “https://code.google.com/p/python-patch/” to patch the diff
    and finally “pip install pycrypto”

  10. Benjamin Montgomery says:

    Great post thanks for writing!

  11. Isaac says:

    Can someone please elaborate on the patch process? I tried the process outlined in the main article I don’t know what to do with Cygwin once I install it. I also tried downloading the py file from “https://code.google.com/p/python-patch/” as mentioned in the previous comment but I’m uncertain as to what to do next. A nOOb worthy walkthrough would be appreciated. Thanks in advance

  12. Isaac says:

    Nevermind, figured it out.

  13. Isaac says:

    This is what I did for patching (Followed another blog post whose URL I’ve since lost:

    if you downloaded the patch.py and diff file in c:\Python27 just run:

    python patch-11.01.py vcvars3.diff

    finally install using pip (google this and follow directions to download):

    pip install pycrypto

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: