本文介绍了“错误:无法找到 vcvarsall.bat"编译 Cython 代码时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

按照此处的建议,我已成功安装Microsoft Visual C++ Compiler for Python 2.7 编译一些 Cython 代码,但是:

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"))

仍然产生:

错误:无法找到 vcvarsall.bat

如何使用 Python 2.7 编译 Cython 代码(例如在 Windows 7 x64 上)?

注意:我已经仔细阅读了问题错误:无法找到 vcvarsall.bat 但主要的答案(包括修改 msvc9compiler.py)没有解决.

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.

推荐答案

我花了几个小时来解决这个问题,但在 错误:无法找到 vcvarsall.bat,这就是为什么我将其发布在这里并带有回答您自己的问题"功能:

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:

备注:您不需要修改msvc9compiler.py,正如许多论坛帖子中经常建议的那样

Remark: You don't need to modify msvc9compiler.py as often suggested in many forum posts

第 2 步:只需添加 import setuptools 即可帮助 Python 和Microsoft Visual C++ Compiler for Python 2.7"协同工作.

Step 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':'.'}})

注意:script_args 参数允许仅使用 python setup.py(即在您最喜欢的编辑器如 Sublime Text 中按 CTRL+B)运行这个 setup.py 而不必通过命令行参数像这样:python setup.py build.

Note: the script_args parameter allows to run this setup.py with just python 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.

有效!

这篇关于“错误:无法找到 vcvarsall.bat"编译 Cython 代码时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 10:26