easy_install -U cython' 失败,报错vcvarsall.bat和-mno-cygwin

11 投票
1 回答
6549 浏览
提问于 2025-04-17 08:29

在Windows系统下,似乎带有C语言依赖的easy_install并不是那么简单。

尝试一 - vcvarsall.bat错误

我在Windows7上安装cython,使用的是MinGw;我把Windows7的PATH环境变量修改为包含C:\MinGw\bin。在这个时候,我尝试运行easy_install -U cython,结果出现了...

C:\Users\mike_pennington\Desktop\TestDrive>easy_install -U cython
Searching for cython
Reading http://pypi.python.org/simple/cython/
Reading http://www.cython.org
Reading http://cython.org
Best match: Cython 0.15.1
Downloading http://cython.org/release/Cython-0.15.1.zip
Processing Cython-0.15.1.zip
Running Cython-0.15.1\setup.py -q bdist_egg --dist-dir c:\users\mike_p~1\appdata
\local\temp\easy_install-qr1tet\Cython-0.15.1\egg-dist-tmp-556kzq
Compiling module Cython.Plex.Scanners ...
Compiling module Cython.Compiler.Scanning ...
Compiling module Cython.Compiler.Parsing ...
Compiling module Cython.Compiler.Visitor ...
Compiling module Cython.Compiler.Code ...
Compiling module Cython.Runtime.refnanny ...
warning: no files found matching 'bugs.txt' under directory 'tests'
error: Setup script exited with error: Unable to find vcvarsall.bat

C:\Users\mike_pennington\Desktop\TestDrive>

尝试二 - 修复vcvarsall.bat错误

接下来,按照我在一个博客上看到的建议,我还尝试把一些内容放到C:\Python27\Lib\distutils\distutils.cfg中,以修复vcvarsall.bat的错误。

[build]
compiler=mingw32

这只稍微有点帮助...

C:\Python27\Lib\DISTUT~1>easy_install -U cython
Searching for cython
Reading http://pypi.python.org/simple/cython/
Reading http://www.cython.org
Reading http://cython.org
Best match: Cython 0.15.1
Downloading http://cython.org/release/Cython-0.15.1.zip
Processing Cython-0.15.1.zip
Running Cython-0.15.1\setup.py -q bdist_egg --dist-dir c:\users\mike_p~1\appdata
\local\temp\easy_install-kfif_o\Cython-0.15.1\egg-dist-tmp-o1tbkp
Compiling module Cython.Plex.Scanners ...
Compiling module Cython.Compiler.Scanning ...
Compiling module Cython.Compiler.Parsing ...
Compiling module Cython.Compiler.Visitor ...
Compiling module Cython.Compiler.Code ...
Compiling module Cython.Runtime.refnanny ...
warning: no files found matching 'bugs.txt' under directory 'tests'
cc1.exe: error: unrecognized command line option '-mno-cygwin'
error: Setup script exited with error: command 'gcc' failed with exit status 1

C:\Python27\Lib\DISTUT~1>

注意 - 不要使用cygwin或预编译的二进制文件

我意识到我可能可以在cygwin下让这个工作;但是,我不想让这个库依赖于cygwin,我需要的是原生的Windows7输出。

如果可以的话,我希望避免使用预编译的Cython二进制文件,因为正如作者所说,它们是“没有支持的,仅供测试使用”。

问题

我该如何在Windows7上使用MinGw通过easy_install安装cython呢?

1 个回答

15

经过一番搜索,我找到了一些建议,推荐把 -mno-cygwinC:\Python27\Lib\distutils\cygwinccompiler.py 文件中删除,因为有一个关于 distutils 的 bug

删除 -mno-cygwin 后,cython 就可以成功编译了。

撰写回答