71

I configured MinGW and distutils so now I can compile extensions using this command:

setup.py install

MinGW's gcc compiler will be used and package will be installed. For that I installed MinGW and created distutils.cfg file with following content:

[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 install <package name>

pip will use MinGW's gcc compiler and compile C code if needed?

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
demalexx
  • 4,661
  • 1
  • 30
  • 34
  • 3
    Another tip: make sure that the file is called *distutils.cfg* and not *distutils.cfg.txt*. Sometimes Windows likes to add the *.txt* extension when you make a new text file. – sffc Jun 18 '15 at 21:31

2 Answers2

107
  • 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
Zoe
  • 27,060
  • 21
  • 118
  • 148
Syl
  • 2,733
  • 2
  • 17
  • 20
  • 3
    The distutils.cfg file creation is what solved this for me - I was trying to install a package with pip and got the dreaded "Unable to find vcvarsall.bat" error. Thanks. – Chad Cooper Nov 09 '11 at 17:03
  • 13
    Remember that you should change this for the python in your virtualenv if you use one. – markijbema Dec 01 '11 at 21:52
  • 7
    Thanks. Still tedious. If only Pip had a `--compiler` option https://github.com/pypa/pip/issues/18 please weigh in – Colonel Panic Aug 16 '12 at 00:01
  • 4
    Just a note, if you are using virtualenv, you have a separate distutils.cfg to change -- this was my problem! – Yablargo Sep 01 '13 at 04:06
  • 2
    I have windows 8.1 on a 64 bit computer. After attempting the above I received the error : `error: You should not use mingw32 for gcc >= 4.6.0. Use mingw64 instead, e.g.:python setup.py build_ext -c mingw64` I altered the `[build]` entry in the distutils.cfg file to read `compiler=mingw32` and had success. – OYRM Aug 02 '14 at 19:39
  • Thank you for precious answer! – Niko Gamulin Aug 13 '14 at 13:44
23

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>
Anton K
  • 4,658
  • 2
  • 47
  • 60