使用Pip安装Python包时如何使用MinGW的gcc编译器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3297254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use MinGW's gcc compiler when installing Python package using Pip?
提问by demalexx
I configured MinGW and distutils so now I can compile extensions using this command:
我配置了 MinGW 和 distutils,所以现在我可以使用以下命令编译扩展:
setup.py install
MinGW's gcc compiler will be used and package will be installed. For that I installed MinGW and created distutils.cfgfile with following content:
将使用 MinGW 的 gcc 编译器并安装包。为此,我安装了 MinGW 并创建了 distutils.cfg文件,其中包含以下内容:
[build]
compiler = mingw32
It's cool but now I'd like to use all pip benefits. Is there a way to use the same MinGW's gcc compiler in pip? So that when I run this:
这很酷,但现在我想使用所有 pip 好处。有没有办法在 pip 中使用相同的 MinGW 的 gcc 编译器?所以当我运行这个时:
pip install <package name>
pip will use MinGW's gcc compiler and compile C code if needed?
如果需要,pip 将使用 MinGW 的 gcc 编译器并编译 C 代码?
Currently I get this error: Unable to find vcvarsall.bat. Seems pip doesn't know that I have gcc compiler. How can I configure pip to use gcc compiler?
目前我收到此错误:Unable to find vcvarsall.bat。似乎 pip 不知道我有 gcc 编译器。如何配置 pip 以使用 gcc 编译器?
回答by Syl
- install MinGW with C++ Compiler option checked
- add
C:\MinGW\binto your PATH - in
PYTHONPATH\Lib\distutils, create a filedistutils.cfgand add these lines:
- 在选中 C++ 编译器选项的情况下安装 MinGW
- 添加
C:\MinGW\bin到您的 PATH - 在 中
PYTHONPATH\Lib\distutils,创建一个文件distutils.cfg并添加以下几行:
[build]
compiler=mingw32
回答by Anton K
Even though configuration file solves this problem, it's not always an option. I had the same issue for my command line installation process and I was not able to change config files on all the machines and python distributions.
尽管配置文件解决了这个问题,但它并不总是一个选项。我的命令行安装过程遇到了同样的问题,我无法更改所有机器和 python 发行版上的配置文件。
This is my solution:
这是我的解决方案:
For mingw32and packages, which use VC++ as default:
对于默认使用 VC++ 的mingw32和包:
pip install --global-option build_ext --global-option --compiler=mingw32 <package_zip>
For Visual C++on WinPython, which uses mingw32 as default:
对于WinPython 上的Visual C++,默认使用 mingw32:
pip install --global-option build_ext --global-option --compiler=msvc <package_zip>

