How to use MinGW's gcc compiler when installing Python package using Pip?

Solution 1:

  • install MinGW with C++ Compiler option checked
  • add C:\MinGW\bin to your PATH
  • in PYTHONPATH\Lib\distutils, create a file distutils.cfg and add these lines:
[build]
compiler=mingw32

Solution 2:

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.

This is my solution:

For mingw32 and packages, which use VC++ as default:

pip install --global-option build_ext --global-option --compiler=mingw32 <package_zip>

For Visual C++ on WinPython, which uses mingw32 as default:

pip install --global-option build_ext --global-option --compiler=msvc <package_zip>