(2019.11.22 has been resolved) Cython error: Unable to find vcvarsall.bat

  • Cython

    passCythonWillPythoncode toC codeand publishPython moduleError during export.

    i.e. throughCythoncompilepyorpyxdocument:

    insert image description here

  • background noun

    • Microsoft Visual C++: referred to as Visual C++, MSVC, VC++ or VC, it is a C++ development tool under the Windows platform developed by Microsoft, with an integrated development environment, which can be used to edit and compile C, C++ and C++/CLI and other programming languages.
    • Microsoft Visual Studio: referred to as VS, it is a series of development tool kits of Microsoft Corporation in the United States. It is a basically complete development tool set, including most of the tools required in the entire software life cycle, such as UML tools, code control tools , including the above integrated development environment Microsoft Visual C++.
    • Internal version number: It can be seen from the above that VS contains VC, and there is a corresponding relationship between the versions. This correspondence is controlled by Microsoft's internal version. The above error message "Microsoft Visual C++ 9.0" is 9.0 It is an internal version of Microsoft Visual C++. We can find out what the corresponding VC version is based on this internal version, and what is the corresponding VS version.
    The corresponding relationship between VS and VC and internal version is as follows:
    VS nameinternal versionVC name
    Visual Studio4.0Visual C++ 4.0
    Visual Studio 975.0Visual C++ 5.0
    Visual Studio 6.06.0Visual C++ 6.0
    Visual Studio .NET 20027.0Visual C++ 2002
    Visual Studio .NET 20037.1Visual C++ 2003
    Visual Studio 20058.0Visual C++ 2005
    Visual Studio 20089.0Visual C++ 2008
    Visual Studio 201010.0Visual C++ 2010
    Visual Studio 201211.0Visual C++ 2012
    Visual Studio 201312.0Visual C++ 2013
    Visual Studio 201413.0Visual C++ 2014
    Visual Studio 201514.0Visual C++ 2015
    Visual Studio 2015 RTM14.0Visual C++ 2015
  • problem explanation

    could not find itvcvarsall.batdesignatedvc++The compiler compiles. Becausewindowsunder the platform,cythonis the callvc++The compiler generatesc filePerform bi generation and compilation to generatepydfile.

    This problem is becauseC compilerThe related configuration is not set.

    Which specific machine is requiredVC++version, see the following files:

    . . ./Python37/Lib/distutils/msvccompiler.py _ _ _ _ _ _ _ _ _ _
    • 1

    Find the following function:

    insert image description here

    which mentions,2.3After version, requiredVCversion insys.versionin, entercmd >> python >> import sys >> sys.versionTo view:

    insert image description here

    inMSC.vthe number after1900is to compile the currentPythonUsedVCversion information, but it is not the internal version number we are looking for, we need to find the major version number from this version informationmajorVersionand minor version numberminorVersion,majorVersion + minorVersionThe result is that we're looking for that build number. then here'smajorVersionandminorVersionHow to get it? We can get from the aboveget_build_version()Find the answer in the function:

    majorVersion =  int ( s [ : - 2 ] )  -  6 
    minorVersion =  int ( s [ 2 : 3 ] )  /  10.0 
    # s is the 1900 above 
    majorVersion =  19  -  6  =  13 
    minorVersion =  00  /  10.0  =  0
    • 1
    • 2
    • 3
    • 4
    • 5

    So, the build number ismajorVersion + minorVersion = 13 + 0.0 = 13.0, according to the above comparison table,


    Looking at the program, there is really no2014:

    insert image description here

    But, the problem is, I can't findVS2014, by introducing here ,Python3.6correspondVS2015.

    PythonMicrosoft Visual StudioCPthon
    Python 2.7Microsoft Visual Studio 2008[MSC v.1500 64 bit (AMD64)]
    Python 3.4Microsoft Visual Studio 2010[MSC v.1600 64 bit (AMD64)]
    Python 3.5Microsoft Visual Studio 2015[MSC v.1900 64 bit (AMD64)]
    Python 3.6Microsoft Visual Studio 2015[MSC v.1900 64 bit (AMD64)]
    Python 3.7Microsoft Visual Studio 2015[MSC v.1912 64 bit (AMD64)]

    Be lazy first, download the smaller Visual C++ Redistributable for Visual Studio 2015 , the installation shows that it already exists, and the installation fails.

    So download and installMicrosoft Visual Studio 2015,problem solved.

  • References

  1. The problem of "Unable to find vcvarsall.bat" when installing the Python extension module under Windows
  2. Correspondence between versions of CPython and Microsoft Visual Studio versions

Related: (2019.11.22 has been resolved) Cython error: Unable to find vcvarsall.bat