Windows under Python 3.6 + VS2017 + Anaconda solve the problem Unable to find vcvarsall.bat

Python 3.6 + VS2017 + Anaconda solve the problem Unable to find vcvarsall.bat

Already installed VS2017, the need to translate the C code project for Python code, python setup.py build when compiling the code setup, there has been error: Unable to find vcvarsall.bat error.

  1. VS2017 find the vcvarsall.batfile, such asC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat

  2. Anaconda open the Lib folder under the distutilsfolder of _msvccompiler.pyfiles, such as:C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\Lib\distutils\_msvccompiler.py

  3. The _find_vcvarsall(plat_spec)function contents replaced with:

def _find_vcvarsall(plat_spec):
    best_dir = r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build'
    best_version = 17
    vcruntime = None
    vcruntime_spec = _VCVARS_PLAT_TO_VCRUNTIME_REDIST.get(plat_spec)
    if vcruntime_spec:
        vcruntime = os.path.join(best_dir,
                                 vcruntime_spec.format(best_version))
        if not os.path.isfile(vcruntime):
            log.debug("%s cannot be found", vcruntime)
            vcruntime = None
    return r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat', vcruntime
  • Question 1: Why install the python extension modules need to install Microsoft Visual C ++ do?

Because some closely related to the underlying operating system Python extension, the use of C / C ++ were written in code, making the need for compilation C / C ++ code during installation, and the Windows platform-specific C / C ++ code compiler tool is Microsoft Visual C ++, Python is a module management tools (e.g., pip) VC default tool is used to compile C / C ++ code is provided. On the Linux platform using C / C ++ code compiler tools they are usually gcc, and therefore does not involve the installation of VS.

  • Question 2: Why install Visual Studio can solve this problem?

As already explained, because Visual Studio is included in Visual C ++, Visual Studio installed after it is installed Visual C ++.

  • Question 3: Why sometimes install the latest version of Visual Studio can not solve this problem?

Since we are using the most current CPython, that is, C language version of Python, we installed on Windows Python is through VC compiled executable program. In order to ensure compatibility with expansion modules using Python module management tools (such as, pip) default when you install external expansion modules C language to find and use the same build and compile Python currently used or compatible internal version the VC, and VS internal version and build of VC it ​​contains is the same, so the installation of VS version is too high or too low may cause problems

Cython fatal error C1083: Can not open include file: "numpy / arrayobject.h": No such file or directory

In the setupinternal addition include_dirs=[np.get_include()], such as:

from distutils.core import setup
from Cython.Build import cythonize
import numpy as np
setup(
    ext_modules=cythonize("dtw.pyx"),
    include_dirs=[np.get_include()]
)

Guess you like

Origin www.cnblogs.com/kanjian2016/p/11443424.html