Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building Python C extension modules for Windows

Tags:

python

windows

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?

like image 541
Will Harris Avatar asked Sep 19 '08 10:09

Will Harris


2 Answers

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/
like image 148
Eli Bendersky Avatar answered Sep 24 '22 13:09

Eli Bendersky


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.

like image 29
Thomas Wouters Avatar answered Sep 22 '22 13:09

Thomas Wouters