如何在虚拟环境中使用MinGW编译Python C扩展?
在Windows上使用virtualenv和MinGW编译器时,编译C扩展会出现以下错误:
C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lpython25 collect2: ld returned 1 exit status error: Setup script exited with error: command 'gcc' failed with exit status 1
要成功编译C扩展,应该怎么做呢?
1 个回答
6
设置 LIBRARY_PATH
环境变量,这样 MinGW 就知道在哪里找到系统中的 Python 文件 libpython25.a
。
在你的虚拟环境的 activate.bat
文件中添加一行:
set LIBRARY_PATH=c:\python25\libs
或者在 Windows 中设置一个全局环境变量。
如果你不是在使用 2.5 版本的 Python,记得把 25
改成你自己 Python 的版本号。