按照建议here ,我已经成功安装Microsoft Visual C++ Compiler for Python 2.7编译一些 Cython 代码,但是:
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize("module1.pyx"))
仍然产生:
error: Unable to find vcvarsall.bat
如何使用 Python 2.7 编译 Cython 代码(例如在 Windows 7 x64 上)?
注意:我已经仔细阅读了问题 error: Unable to find vcvarsall.bat但主要答案(包括修改msvc9compiler.py
)并没有解决。
最佳答案
我在这上面花了几个小时,而且在 error: Unable to find vcvarsall.bat 中不容易找到信息,这就是为什么我将它发布在这里并带有“回答你自己的问题”功能:
注意:您不需要像许多论坛帖子中经常建议的那样修改
msvc9compiler.py
第 2 步:只需添加
import setuptools
即可帮助 Python 和“Microsoft Visual C++ Compiler for Python 2.7”协同工作。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':'.'}})
注意:
script_args
参数允许仅使用python setup.py
运行此 setup.py(即在您喜欢的编辑器(如 Sublime Text)中按 CTRL+B)instead of having to pass command-line arguments这:python setup.py 构建
。
有效!
关于python - 编译Cython代码时出现"error: Unable to find vcvarsall.bat",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53172601/