Installing pycrypto on Windows 8

While trying to install pycrypto on Windows 8, because it was a requirement for “paramiko” which I needed for some SSH stuff, I kept running into failure after another. To summarise, you need to have Visual Studio 2008 installed (there is an express version available free, and there is also likely a microsoft SDK package that includes the Visual C++ 9.0 compiler). After sorting all of these out however, I still had one persistent type of problem:

warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
 Traceback (most recent call last):
 File "<string>", line 1, in <module>
 File "c:\users\fanen\appdata\local\temp\pip_build_Fanen\pycrypto\setup.py", line 456, in <module>
 core.setup(**kw)
 File "c:\Python27\lib\distutils\core.py", line 152, in setup
 dist.run_commands()
 File "c:\Python27\lib\distutils\dist.py", line 953, in run_commands
 self.run_command(cmd)
 File "c:\Python27\lib\distutils\dist.py", line 972, in run_command
 cmd_obj.run()
 File "c:\Python27\lib\site-packages\setuptools\command\install.py", line 53, in run
 return _install.run(self)
 File "c:\Python27\lib\distutils\command\install.py", line 563, in run
 self.run_command('build')
 File "c:\Python27\lib\distutils\cmd.py", line 326, in run_command
 self.distribution.run_command(command)
 File "c:\Python27\lib\distutils\dist.py", line 972, in run_command
 cmd_obj.run()
 File "c:\Python27\lib\distutils\command\build.py", line 127, in run
 self.run_command(cmd_name)
 File "c:\Python27\lib\distutils\cmd.py", line 326, in run_command
 self.distribution.run_command(command)
 File "c:\Python27\lib\distutils\dist.py", line 972, in run_command
 cmd_obj.run()
 File "c:\users\fanen\appdata\local\temp\pip_build_Fanen\pycrypto\setup.py", line 253, in run
 build_ext.run(self)
 File "c:\Python27\lib\distutils\command\build_ext.py", line 337, in run
 self.build_extensions()
 File "c:\users\fanen\appdata\local\temp\pip_build_Fanen\pycrypto\setup.py", line 150, in build_extensions
 build_ext.build_extensions(self)
 File "c:\Python27\lib\distutils\command\build_ext.py", line 446, in build_extensions
 self.build_extension(ext)
 File "c:\Python27\lib\distutils\command\build_ext.py", line 496, in build_extension
 depends=ext.depends)
 File "c:\Python27\lib\distutils\msvc9compiler.py", line 475, in compile
 self.initialize()
 File "c:\Python27\lib\distutils\msvc9compiler.py", line 385, in initialize
 vc_env = query_vcvarsall(VERSION, plat_spec)
 File "c:\Python27\lib\distutils\msvc9compiler.py", line 301, in query_vcvarsall
 raise ValueError(str(list(result.keys())))
 ValueError: [u'path']

It appears that the function “query_vcvarsall” fails if it doesn’t find a set of 4 environment variables (this is some dodgy coding to me :p):

  • path
  • include
  • lib
  • libpath

You may need to create these environment variables, and place in them the appropriate paths for your PC.

On my 64-bit windows 8 machine with 64-bit Python 2.7.6, I have the following:

LIB = C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ATLMFC\LIB;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\LIB;%WindowsSdkDir%lib;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib;C:\Python27\Lib;%LIB%
INCLUDE = C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ATLMFC\INCLUDE;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE;%WindowsSdkDir%include;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include;C:\Python27\include;%INCLUDE%
PATH = C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools;C:\WINDOWS\Microsoft.NET\Framework\v3.5;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\VCPackages;%WindowsSdkDir%bin;C:\Python27\Scripts;C:\Python27;%PATH%
LIBPATH = C:\WINDOWS\Microsoft.NET\Framework\v3.5;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ATLMFC\LIB;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\LIB;C:\Python27\Lib;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib;%LIBPATH%

After that, I am able to use pip to install pycrypto.

Note that my variables may contain paths which are redundant, but I arrived there after a windy path of experimentation. After It worked, I said to myself: “if it ain’t broke, don’t fix it.”

The following site was very helpful in showing me alternative ways. I like what the guy did to the python utility scripts. Just hack them to do what I want. None of the cruft of general-purpose code. Just tell the bloody system I have Visual Studio 9.0 😉 http://blog.victorjabur.com/2011/06/05/compiling-python-2-7-modules-on-windows-32-and-64-using-msvc-2008-express/

 

 

2 thoughts on “Installing pycrypto on Windows 8

  1. I haven’t tested this yet, but after already spending a regrettable amount of time at work on this problem I can only thank you immensely for the tips.

Leave a Reply