3

I'm trying to build a simple C++ extension module for Blender through their Python API which, as of the latest version, is 3.5.3 (to my knowledge, one cannot change this). Python 3.5.3 is compiled with MSC v.1800 (i.e., Visual Studio 2013 version 12.0).

I have both Visual Studio 2013 and Visual Studio 2017 installed. When running distutils.setup(...) in my "setup.py" for the extension, it invariably finds only Visual Studio 2017, causing the build to fail (one must match the Visual Studio version to the Python version [1] ).

How can I convince distutils.setup(...) to find the Visual Studio corresponding to the Python that's running?

I tried prepending the Visual Studio 2013 path to the PATH, which does nothing. I also dug into "Lib/distutils/" to try to figure it out, but couldn't (looks like it's registry-based, not PATH-based).


[1] Or else, one gets the mysterious, undocumented error LNK1327: failure during running rc.exe. This is the entire error, though there is also a minor warning before it, which is apparently normal.

geometrian
  • 14,775
  • 10
  • 56
  • 132

1 Answers1

2

The following code sets two environment variables which were (obscurely) documented as a fallback for when the compiler detection fails.

Then, we call "vcvarsall.bat". Python apparently requires the 8.1 Windows SDK, and only the Visual Studio 2017 version of "vcvarsall.bat" supports that. So, we call the 2017 version, but pass -vcvars_ver=12.0 to set for 2013.

SET MSSdk=1
SET DISTUTILS_USE_SDK=1
call "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/vcvarsall.bat" amd64 8.1 -vcvars_ver=12.0

Then, you can run your:

python35.exe setup.py build
geometrian
  • 14,775
  • 10
  • 56
  • 132
  • Setting `MSSdk` should be unnecessary as of Python 3.5. `DISTUTILS_USE_SDK` is the only value required for bypassing detection. – Zooba Sep 17 '18 at 16:21