Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cython pyximport error on Windows

Tags:

mingw

cython

I'm making my first steps with Cython, and I've installed it on my machine according to the instructions in the wiki.

Working through the Cython tutorial I got to pyximport, which is supposed to make cython compilation really simple. When I tried using it, though, I got the following error message (reformatted):

ImportError: Building module failed: 
DistutilsPlatformError('
    Python was built with Visual Studio 2003;
    extensions must be built with a compiler than can generate compatible binaries.
    Visual Studio 2003 was not found on this system. If you have Cygwin installed,
    you can try compiling with MingW32, by passing "-c mingw32" to setup.py.',)

So my question is: anyone know of a way to make pyximport use mingw?

Note that mingw seems to be installed properly, the long way to make Cython modules (using setup.py) did work for me, and that I even created a distutils.cfg file like the wiki told me.

like image 540
itsadok Avatar asked Jun 03 '09 08:06

itsadok


3 Answers

I was recently mucking around and discovered the setup_args argument of pyximport.install. This works for me:

mingw_setup_args={'options': {'build_ext': {'compiler': 'mingw32'}}}
import pyximport; pyximport.install(setup_args=mingw_setup_args)
like image 147
MEmmett Avatar answered Nov 13 '22 12:11

MEmmett


maybe this way (from mail list):

c:\Python2x\Lib\distutils\distutils.cfg:

[build]
compiler = mingw32

[build_ext]
compiler = mingw32 
like image 10
sunqiang Avatar answered Nov 13 '22 10:11

sunqiang


You can also create a "pydistutils.cfg" file under your home so that you get either of those paths: "C:\Documents and Settings\YourUsername\pydistutils.cfg" or "C:\Users\YourUsername\pydistutils.cfg".

Then add:

[build_ext]

compiler=mingw32

to that file. Also make sure you have "MinGW"'s gcc on your path. From that point on, when you use "import pyximport; pyximport.install()", cython should generate a folder named ".pyxbld" under your home folder(See Above). On windows, this folder will contain all of the " .c, .o, .pyd, .def" files generated by cython.

Happy cythoning!

like image 1
user258030 Avatar answered Nov 13 '22 12:11

user258030