python - 如何在 virtualenv 中使用 MinGW 编译 Python C 扩展?

标签 python mingw virtualenv

在 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 扩展,应该怎么做?

最佳答案

设置 LIBRARY_PATH 环境变量,以便 MinGW 知道在哪里可以找到系统范围的 Python libpython25.a

在 virtualenv 的 activate.bat 中放置一行:

set LIBRARY_PATH=c:\python25\libs

或者在 Windows 中设置全局环境变量。

如果您不使用 2.5 版本,请务必更改 25 以对应您的 Python 版本。

关于python - 如何在 virtualenv 中使用 MinGW 编译 Python C 扩展?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1015605/

相关文章:

python - pandas 没有将类型 string 转换为 float

python - 从十六进制字符串中删除 0x

linux - 使用命令行对多个文件执行命令

django - Salt - virtualenv 的多个需求文件

python - Django-admin 在 vi​​rtualenv 中创建了错误的 django 版本

python - 如何仅使用 virtualenv 引导脚本在虚拟环境中安装 python 包?

python - TensorFlow 中的变量到底是什么?我们为什么要使用它们?

python - 将 np.zeros 与 OpenCV 结合使用时,图像看起来曝光过度(几乎全白) imshow

为 Windows 平台构建的 Qt X11 应用程序

c++ - 使用 CMake 包含 OpenCV 库 dll