我在 Windows 64 位计算机上安装了 Python 2.7 的“Enthought Canopy”v1.5 发行版和 cython 0.22(通过 Canopy 包管理器安装)。尝试编译 cython 文件会导致以下错误:
building 'my_cython_extension' extension
error: Could not find Visual Studio 2008 in your path.
If you do not have Visual Studio 2008 installed, you can use
the MinGW compiler instead. To install mingw, do:
enpkg mingw
To use the MinGW compiler to build an extension module, use
the '-c' flag, e.g.:
python setup.py build_ext -c mingw64
Note that building Python extensions with MinGW is not officially
supported, although it is known to work in many cases.
Visual Studio 2008 不再可用,并且 Visual Studio 2008 Express 不包含 64 位编译器。我读到有必要使用与编译 Python 相同的编译器来编译 cython,这排除了使用较新版本的 Visual Studio 的可能性。此外,该消息明确指出 MinGW 不受官方支持。
我尝试按照 Microsoft Visual C++ Compiler for Python 2.7 安装“Cython Wiki ” ,但这对使上述错误消息消失没有影响。我读过更新 setuptools
可能会修复此错误(因为它可以在与旧版本期望找到的位置不同的位置找到编译器),但这对我来说不起作用,另外 Enthought有stated on their website那:
Setuptools 0.6 is already supported, and higher versions are not yet compatible with Enthought installers.
...所以更新 setuptools 可能会破坏 Canopy 中的某些内容。
最后,我尝试安装“MS Windows SDK for Windows 7 and .NET Framework 3.5 SP1”(稍后在 cython Wiki 中编写),但这也没有使消息消失,而且它是一个巨大的如果可能的话,我宁愿不为编译器安装笨重的软件包。
那么,有没有办法让“Microsoft Visual C++ Compiler for Python 2.7”与 cython 和 Enthought Canopy 一起工作?如果没有,安装和配置 cython 编译器的官方方法是什么?
最佳答案
我花了一天的大部分时间来弄清楚如何让它工作,我真诚地希望有更好的方法,我很想听听,但这就是为我完成工作的方法:
1) 安装 Microsoft Visual C++ 2008 Express 版本 - 您应该通过 Google 搜索找到它的直接下载链接。
2) 从 here 下载“Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1 (ISO)”镜像(请务必选择 64 位版本 GRMSDKX_EN_DVD.iso
)
3) 使用 7-zip 解压 iso,或使用您喜欢的软件安装/刻录
4) 运行setup.exe并安装。您可以安全地取消选择除“Visual C++ 编译器”和“Windows header 和库”之外的所有内容
5) 将文件 C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat
复制到文件夹 C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\
并将其重命名为 vcvarsamd64.bat
6) 不确定这是否有必要,但您可能需要在 Visual Studio 命令提示符中运行以下命令,如 cython wiki 中所写
set DISTUTILS_USE_SDK=1
setenv /x64 /release
注释 1:第 1 步似乎是必要的,因为 .net 3.5 的 64 位 Windows SDK 似乎没有附带 vcvarsall.bat
文件。
注 2:第 5 步是必要的,因为 Visual C++ 2008 Express 附带的 vcvarsall.bat
指向 64 位编译器的错误位置。
关于python - 在 64 位 Windows 上让 cython 与 Enthought Canopy 配合使用的官方方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28959378/