问题
As suggested here, I have succesfully installed Microsoft Visual C++ Compiler for Python 2.7 to compile some Cython code, but:
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize("module1.pyx"))
still produces:
error: Unable to find vcvarsall.bat
How to compile Cython code with Python 2.7 (for example on Windows 7 x64)?
Note: I already carefully read the question error: Unable to find vcvarsall.bat but the main answers (including modifying msvc9compiler.py
) didn't solve it.
回答1:
I spent hours on this, and the information was not easily findable in error: Unable to find vcvarsall.bat, that's why I post it here with the "answer your own question" feature:
Step 1: Install Microsoft Visual C++ Compiler for Python 2.7
Remark: You don't need to modify
msvc9compiler.py
as often suggested in many forum postsStep 2: Just add
import setuptools
that will help Python and "Microsoft Visual C++ Compiler for Python 2.7" work together.import setuptools # important from distutils.core import setup from Cython.Build import cythonize setup(ext_modules=cythonize("module1.pyx", build_dir="build"), script_args=['build'], options={'build':{'build_lib':'.'}})
Note: the
script_args
parameter allows to run this setup.py with justpython setup.py
(i.e. CTRL+B in your favorite editor like Sublime Text) instead of having to pass command-line arguments like this:python setup.py build
.
It works!
来源:https://stackoverflow.com/questions/53172601/error-unable-to-find-vcvarsall-bat-when-compiling-cython-code