Installation Cython错误:C:\Python27\libs/libpython27。a:添加符号时出错

Installation Cython错误:C:\Python27\libs/libpython27。a:添加符号时出错,installation,cython,Installation,Cython,我正在和Cython做第一次测试。基本上是来自 当我想要编译时,我得到以下错误: C:[...]>python setup.py build_ext --inplace Compiling hello.pyx because it changed. [1/1] Cythonizing hello.pyx running build_ext building 'hello' extension C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python27

我正在和Cython做第一次测试。基本上是来自

当我想要编译时,我得到以下错误:

C:[...]>python setup.py build_ext --inplace
Compiling hello.pyx because it changed.
[1/1] Cythonizing hello.pyx
running build_ext
building 'hello' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c he
llo.c -o build\temp.win32-2.7\Release\hello.o
writing build\temp.win32-2.7\Release\hello.def
C:\MinGW\bin\gcc.exe -shared -s build\temp.win32-2.7\Release\hello.o build\temp.
win32-2.7\Release\hello.def -LC:\Python27\libs -LC:\Python27\PCbuild -lpython27
-lmsvcr90 -o C:\Users\Bernd\Documents\99_Projekte\ONGOING\201412_Laufauswertung\
Repro\Tests\hello.pyd
C:\Python27\libs/libpython27.a: error adding symbols: File format not recognized

collect2.exe: error: ld returned 1 exit status
error: command 'C:\\MinGW\\bin\\gcc.exe' failed with exit status 1
生成文件
hello.c

有什么想法吗

编辑1:

根据J.J.Hakala的提示,我做了如下操作:将
libpython27.a
C:\Python27\libs
(例如bak子目录)中移出,并将
Python27.dll
C:\windows\system32复制到C:\Python27\libs

现在的结果是:

C:[...]>python setup.py build_ext --inplace
running build_ext
building 'hello' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c he
llo.c -o build\temp.win32-2.7\Release\hello.o
writing build\temp.win32-2.7\Release\hello.def
C:\MinGW\bin\gcc.exe -shared -s build\temp.win32-2.7\Release\hello.o build\temp.
win32-2.7\Release\hello.def -LC:\Python27\libs -LC:\Python27\PCbuild -lpython27
-lmsvcr90 -o C:\Users\Bernd\Documents\99_Projekte\ONGOING\201412_Laufauswertung\
Repro\Tests\hello.pyd
build\temp.win32-2.7\Release\hello.o:hello.c:(.text+0x2d9): undefined reference
to `_imp___PyThreadState_Current'
build\temp.win32-2.7\Release\hello.o:hello.c:(.text+0x3b3): undefined reference
to `_imp__PyExc_RuntimeError'
build\temp.win32-2.7\Release\hello.o:hello.c:(.text+0x444): undefined reference
to `_imp___Py_NoneStruct'
build\temp.win32-2.7\Release\hello.o:hello.c:(.text+0x8e1): undefined reference
to `_imp__PyExc_ImportError'
collect2.exe: error: ld returned 1 exit status
error: command 'C:\\MinGW\\bin\\gcc.exe' failed with exit status 1
生成一个文件夹
build\temp.win32-2.7\Release
,其中包含文件
hello.def
hello.o

编辑2: 也许解决方案就在这里:

我将尝试安装Visual Studio,然后重试。关于如何使其在MinGW上运行的建议仍然存在。

如果安装了工具gendef和dlltool,则在临时目录中应该可以执行以下操作(假设msys或cygwin环境):

如有必要,替换C:/Python27


gcc现在将使用生成的文件,而不是一些现有的
.a
.lib
文件。

您可以测试以下内容:将
libpython27.a
从C:\Python27\libs(例如bak子目录)移走,并将
Python27.dll
从C:\windows\system32复制到C:\Python27\libs谢谢您的提示J Hakala。我感觉我们取得了一些进展,尽管仍然没有工作。有关详细信息,请参见编辑。编译时添加
-mthreads
是否会改善这种情况?我注意到我的cython相关Makefile中有这个标志。
python setup.py build\u ext--inplace-mthreads
确实提供了
选项-m未被识别
。我没有尝试安装
dlltool
gendef
。好消息:完成此操作后,
python setup.py build\u ext--inplace
将在没有任何错误的情况下运行。使用
*.gen*.o*.pyd
文件生成文件夹
release
。我只是感到困惑,因为我没有找到
*.exe
文件。那么在哪里可以找到Windows可执行文件呢?(如果我在这里有一些误解,很抱歉)@BerndGit您构建了一个python扩展模块,而不是一个独立的可执行文件。当您执行导入hello时,扩展模块提供的类和函数将可用。好的,谢谢。我在网站上找到了后续问题的答案
gendef c:/Windows/System32/python27.dll
dlltool -U -d python27.def -l libpython27.dll.a
cp libpython27.dll.a c:/Python27/libs