12

I have a C extension module and it would be nice to distribute built binaries. Setuptools makes it easy to build extensions modules on OS X and GNU/Linux, since those OSs come with GCC, but I don't know how to do it in Windows.

Would I need to buy a copy of Visual Studio, or does Visual Studio Express work? Can I just use Cygwin or MinGW?

Will Harris
  • 21,597
  • 12
  • 64
  • 64

2 Answers2

16

You can use both MinGW and VC++ Express (free, no need to buy it).

See:

  1. http://eli.thegreenplace.net/2008/06/28/compiling-python-extensions-with-distutils-and-mingw/
  2. http://eli.thegreenplace.net/2008/06/27/creating-python-extension-modules-in-c/
Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
  • Thanks. Your guide to compiling extensions with mingw worked perfectly. – Will Harris Dec 21 '08 at 18:24
  • Hey just wanted to let you know, I followed your guide under #1 (using the setup.py and hellomodule.c files provided in footnote 1 of the article) and everything worked like a charm. I am using Windows XP 32 bit, Python 2.6 and MinGW 4.5.0. I did not have to mess around with that .a/.dll stuff. Thanks! – oob Sep 14 '10 at 04:01
  • There's also [this reference](http://blog.victorjabur.com/2011/06/05/compiling-python-2-7-modules-on-windows-32-and-64-using-msvc-2008-express/). – Craig McQueen Nov 20 '13 at 08:24
  • Where can we find which version of VC++ was used to build a particular release of Python? How important is it to use the same version of VC++? – Craig McQueen Nov 20 '13 at 08:25
3

Setuptools and distutils don't come with gcc, but they use the same compiler Python was built with. The difference is mostly that on the typical UNIX system that compiler is 'gcc' and you have it installed.

In order to compile extension modules on Windows, you need a compiler for Windows. MSVS will do, even the Express version I believe, but it does have to be the same MSVC++ version as Python was built with. Or you can use Cygwin or MinGW; See the appropriate section of Installing Python Modules.

Craig McQueen
  • 41,871
  • 30
  • 130
  • 181
Thomas Wouters
  • 130,178
  • 23
  • 148
  • 122
  • 2
    I am stumbled by the fact that you cannot use VS 2005 or newer, but you can use MinGW (a completely different compiler!)... – Roman Plášil Feb 21 '10 at 11:01
  • 1
    This is just a recommendation. I am continuously creating PYDs for all Python versions 2.7 through 3.6 with the same VS 2013 compiler and never saw a problem. – Jorj McKie Dec 01 '17 at 11:34