python - 编译Cython代码时出现"error: Unable to find vcvarsall.bat"

标签 python windows visual-c++ cython distutils

按照建议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 中不容易找到信息,这就是为什么我将它发布在这里并带有“回答你自己的问题”功能:

  • 第 1 步:安装 Microsoft Visual C++ Compiler for Python 2.7

  • 注意:您不需要像许多论坛帖子中经常建议的那样修改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/

相关文章:

windows - 批处理文件调用 vbs 不会从任务计划程序运行

Windows 语言包与本地化版本

c++ - Cryptopp.dll访问冲突读取位置0x74736554

C++ 芯片对计算问题

c++ - vc++(vs2008)有没有什么工具可以提高intellisense?

python - 将自定义 Docker 与 Azure ML 结合使用

python - 如何将我的 python 代码转换为在 GPU 而不是 CPU 上运行?

python - 计算每列的不同值,返回数据框并对值进行排序

python - 如何像 R 一样将变量从 Python 脚本导入到交互式 shell 中?

windows - 如何通过 API 查询 Windows Phone 7 电话号码?