且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用Cython不会在Windows 7 64位编译

更新时间:2023-09-30 12:59:28

有pre-编译用Cython包的这个网站。我建议你​​改用x86的Python中,你没有获得真正的优势,通过使用64位版本。如果你想坚持的X64,你不能使用MinGW和您必须使用MS SDK C ++编译器(更多关于这个

  

不使用的MinGW-W64 。正如你会发现,MinGW的导入库   为Python(如libpython27.a)从AMD64版本省略   蟒蛇。这是经过深思熟虑的。   不要试图用dlltool做一个。   [...]也有一些与MinGW的运行时问题   随着MSVC运行时发生冲突;这可以从地方发生您   不要指望,如内部运行时库G ++或gfortran。

I'm struggling with installing Cython on Windows 7 x64. I downloaded and installed the automated MinGW installer. The created a distutils.cfg to the distutils folder with the following content:

[build]
compiler = mingw32

After adding C:\MinGW\bin to the environment variables, I called easy_install Cython but I get the following errors. Raping the internet did really not give me helpful resulsts as all this compiling stuff (or should I say sh*t ?) is so new to me.

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

Any ideas whats wrong ? Thanks !

UPDATE: I used dlltools to create libpython27.a and then again tried to build Cython and it just worked fine ! But now, calling cython.exe delivers this error:

ImportError: DLL load failed, %1 is not a valid Win32-executable.

I assume this is because I use Pythonx64 but the MinGW32 compiler ? So, how can i compile it for x64 ?

There are pre-compiled Cython packages on this site. I'd suggest you to switch to x86 Python, you gain no real advantage by using the x64 version. If you want to stick with x64, you can't use MingW and you have to use MS SDK C++ compiler (more on this).

Do not use MinGW-w64. As you will notice, the MinGW import library for Python (e.g. libpython27.a) is omitted from the AMD64 version of Python. This is deliberate. Do not try to make one using dlltool. [...] There have also been issues with the mingw runtime conflicting with the MSVC runtime; this can happen from places you don't expect, such as inside runtime libraries for g++ or gfortran.