Python on Windows not using Visual Studio C++ compiler

My current work has me using Python2.7, which on occasion requires a package with some yummy C++ at it’s core.  Obviously this will require compiling before it can be used.  This is handled by “pip” quite nicely, but it can be a little brain dead.

As I am also working with various other languages I have Visual Studio 2015 installed, with C++.  So when I came to install a package and pip claimed there was no C++ compiler and to download a custom C++ 9.0 package from Microsoft specifically for Python I was a little confused.. (SPOILER: The Microsoft package, whilst nice of them does seem to be missing a few headers.. stdint.h for one.. *sigh*)..

Anyway, thankfully there is quite a simple fix via the power of environment variables.  If you run the command “env” within a command prompt you will get a list of that instances current environment variables.   Look through them and you should find (in the case of Visual Studio 2015) something like: (If you have a different version of VS installed you will see a different VSnnn)

VS140COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\

Now what the Python build environment is looking for (in the case of 2.7) is “VS90COMNTOOLS” environment variable…

Thankfully the Microsoft compiler takes the same options between versions, so a quick fix is simply:

set VS90COMNTOOLS=%VS140COMNTOOLS%

which will set the environment variable Python2.7 is looking for to point at the VS install.. hey presto!

However! this will only affect the Command Prompt you are currently using.  If you wish to make this more permanent, you should set this on your systems environment variables within control panel (and remember to restart your Command Prompts!)

 

Leave a Reply

Your email address will not be published. Required fields are marked *