The solution of Python extension problem “unable to find vcvarsall. Bat”

When using C to write extensions to python3, we encountered the following problems:

Write * module. C and setup. Py files and execute them

python setup.py build

Unable to find vcfarsall.bat

I have VS2005 and VC6 on my machine, but I still report an error

Search a lot of information:

Online solutions are as follows:

Download MinGW environment and add environment variables

Use

python setup.py build –compiler=mingw32

I feel that this method just bypasses this problem, but it is not really a solution. Moreover, in my system, Python is compiled with VS, but the extension module is compiled with MinGW GCC. I feel that there may be a problem

But there is no detailed explanation on the Internet

After carefully reading the. Py file in the C/Python 32/lib/distutils directory, it is found that the sentence “unable to find vcvar sall. Bat” is in msvc9compiler. Py

Further study of this document reveals the problem

It looks for the vs directory in the registry, and then looks for vcvarsall.bat in the vs directory

But the problem is that in python32, the default is vc9.0, which is VS2008, so it can’t find the key value in the registry and returns none

productdir = Reg.get_ value(r”%s/Setup/VC” % vsbase,

“productdir”)

The value of vsbase is: software/Microsoft/Visual Studio/9.0

The specific modification code is as follows:

In msvc9compiler.py

def find_ Vcvarsall (version) is used to find vcvarsall. Bat version, which is the version number, is actually 9.0

vc_ env = query_ vcvarsall(VERSION, plat_ spec)

VERSION = get_ build_ Version () because python32 itself is built by vc9.0, version is 9.0

Modify the msvccompiler function:

vc_env = query_vcvarsall(VERSION, plat_spec)

For:

vc_env = query_vcvarsall(8.0, plat_spec)

But there is another sentence:

if VERSION < 8.0:
 
raise DistutilsPlatformError("VC %0.1f is not supported by this module" % VERSION)

It seems that distutils in Python 3.2 only supports compilers above VC8.0, that is, compilers above VS2005

Similar Posts: