Skip to main content
 首页 » 编程设计

python之无法在 Windows 10 上使用 python2.7/MINGW 安装 pyslalib 包

2025年05月04日28unruledboy

我正在尝试安装 pyslalib package在 Windows 10 上使用 python 2.7 并继续获得以下信息:

“collect2.exe:错误:ld 返回了 1 个退出状态”

当我尝试运行“python setup.py install”时出现的消息。我认为这可能是我的 mingw 配置的问题,但我似乎无法找到问题所在。

如果您对此问题有任何帮助,我们将不胜感激。周末的大部分时间我都在为此苦苦挣扎。

谢谢,

输出错误是:

C:\Python27\libs/libpython27.a(dmmes01026.o):(.idata$7+0x0): undefined reference to `_head_C__build27_cpython_PCBuild_libpython27_a' 
C:\Python27\libs/libpython27.a(dmmes00281.o):(.idata$7+0x0): undefined reference to `_head_C__build27_cpython_PCBuild_libpython27_a' 
C:\Python27\libs/libpython27.a(dmmes00105.o):(.idata$7+0x0): undefined reference to `_head_C__build27_cpython_PCBuild_libpython27_a' 
C:\Python27\libs/libpython27.a(dmmes00253.o):(.idata$7+0x0): undefined reference to `_head_C__build27_cpython_PCBuild_libpython27_a' 
C:\Python27\libs/libpython27.a(dmmes00227.o):(.idata$7+0x0): undefined reference to `_head_C__build27_cpython_PCBuild_libpython27_a' 
C:\Python27\libs/libpython27.a(dmmes00712.o):(.idata$7+0x0): more undefined references to `_head_C__build27_cpython_PCBuild_libpython27_a' follow 
collect2.exe: error: ld returned 1 exit status 

请您参考如下方法:

这看起来像是我最近遇到的一个问题。我认为 Python 附带的 libpython27.a 有问题(我使用的是 2.7.10 版)。根据找到的说明从 python27.dll 创建我自己的 libpython27.a here解决了问题。

To create Python extensions, you need to link against the Python library. Unfortunately, most Python distributions are provided with Python22.lib, a library in Microsoft Visual C++ format. GCC expects a .a file (libpython22.a to be precise.). Here's how to convert python22.lib to libpython22.a:

  1. Download pexport (from here or https://web.archive.org/web/20000829082204/http://starship.python.net/crew/kernr/mingw32/pexports-0.42h.zip).
  2. Get Python22.dll (it should be somewhere on your harddrive).
  3. Run : pexports python22.dll > python22.def This will extract all symbols from python22.dll and write them into python22.def.
  4. Run : dlltool --dllname python22.dll --def python22.def --output-lib libpython22.a This will create libpython22.a (dlltool is part of MinGW utilities).
  5. Copy libpython22.a to c:\python22\libs\ (in the same directory as python22.lib).

This trick should work for all Python versions, including future releases of Python. You can also use this trick to convert other libraries.