如何建立我的C扩展使用MinGW-W64在Python

Python019

如何建立我的C扩展使用MinGW-W64在Python,第1张

安装Python的 windows扩展模块时发生Unable to find vcvarsall.bat的错误,解决方法如下: 首先安装MinGW,在MinGW的安装目录下找到bin的文件夹,找到mingw32-make.exe,复制一份更名为make.exe; 把MinGW的路径添加到环境变量path中,

首先,把python.exe加入PATH环境变量。

这个操作方法很容易百度到。加完了重启,然后在cmd里 任意目录下,执行:

python --version

应该返回python的版本信息。这时说明配置好了。

然后,再回去试

python setup.py build --compiler=mingw32 install

使用MinGW 编译python扩展模块

MinGW:一个可自由使用和自由发布的Windows特定头文件和使用GNU工具集导入库的集合,

允许你生成本地的Windows程序而不需要第三方C运行时库。说白了就是在windows环境下

提供一套GNU工作环境。

1、下载mingw-get

下载地址

2、 安装gcc

mingw-get install gcc

3、安装mingw32-make

mingw-get install mingw32-make

4、添加mingw/bin到path变量中

5、指定编译器为mingw32

python setup.py build -c mingw32 install

python setup.py build --complier=mingw32 install

或者修改site.cfg中添加或修改

[build]

compiler = mingw32

或者在lib\distutils\distutils.cfg添加或修改

[build]

compiler = mingw32

上面几种方结果一样只是操作过程中影响的范围不同而已.