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:
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!)