Cython在Windows 7 x64上无法编译
我在Windows 7 x64上安装Cython时遇到了麻烦。我下载并安装了自动化的MinGW安装程序
。这个程序在distutils文件夹里创建了一个distutils.cfg文件,内容如下:
[build]
compiler = mingw32
在把C:\MinGW\bin
添加到环境变量后,我运行了easy_install Cython
,但是出现了以下错误。我在网上搜索了很久,但这些编译的东西对我来说实在是太陌生了,根本没有找到有用的结果。
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x5d59): undefined reference to `_imp__PyObject_GetAttr'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x5dc5): undefined reference to `_imp__PyObject_GetAttr'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x5e31): undefined reference to `_imp__PyObject_GetAttr'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x5ebc): undefined reference to `_imp__PyObject_Call'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x5f08): undefined reference to `_imp__PyDict_New'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x5f49): undefined reference to `_imp__PyObject_SetAttr'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x5ffe): undefined reference to `_imp__PyErr_Occurred'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x6013): undefined reference to `_imp__PyExc_ImportError'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x601e): undefined reference to `_imp__PyErr_SetString'
c:\users\niklas\appdata\local\temp\easy_install-dgjjub\cython-0.15\cython\plex\scanners.o:Scanners.c:(.text+0x602d): undefined reference to `_imp__PyInt_FromLong'
collect2: ld returned 1 exit status
dllwrap: gcc exited with status 1
error: Setup script exited with error: command 'dllwrap' failed with exit status 1
有没有人知道哪里出了问题?谢谢!
更新:我用dlltools创建了libpython27.a,然后再次尝试构建Cython,这次成功了!但是现在,运行cython.exe时又出现了这个错误:
ImportError: DLL load failed, %1 is not a valid Win32-executable.
我猜这是因为我使用的是Python x64,但编译器却是MinGW32?那么,我该如何为x64编译呢?
1 个回答
11
在这个网站上有一些已经编译好的Cython包。我建议你使用x86版本的Python,因为使用x64版本并不会给你带来实际的好处。如果你坚持要用x64版本,那就不能用MingW,你必须使用MS SDK的C++编译器(了解更多信息)。
不要使用MinGW-w64。你会发现,Python的MinGW导入库(比如libpython27.a)在AMD64版本的Python中是缺失的。这是故意的。不要试图用dlltool去创建一个。[...] 另外,mingw的运行时可能会和MSVC的运行时发生冲突;这种情况可能会在你意想不到的地方发生,比如在g++或gfortran的运行时库中。