itsadok
itsadok

Reputation: 29342

Cython pyximport error on Windows

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.

Upvotes: 5

Views: 3681

Answers (3)

user258030
user258030

Reputation: 399

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!

Upvotes: 1

sunqiang
sunqiang

Reputation: 6492

maybe this way (from mail list):

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

[build]
compiler = mingw32

[build_ext]
compiler = mingw32 

Upvotes: 10

MEmmett
MEmmett

Reputation: 131

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)

Upvotes: 13

Related Questions