“错误:无法找到vcvarsall.bat”编译Cython代码时 [英] "error: Unable to find vcvarsall.bat" when compiling Cython code

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

问题描述

按照建议的此处,我已经成功安装了用于Python 2.7的Microsoft Visual C ++编译器可以编译一些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

error: Unable to find vcvarsall.bat

如何使用以下命令编译Cython代码Python 2.7(例如,在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 ,这就是为什么我在此处将其与 answer your自己的问题功能:

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和 Python 2.7的Microsoft Visual C ++编译器协同工作。

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代码时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆