4
votes

I am trying to get cython to realize I have a c compiler in MinGW 32-bit and I've tried everything I can find on the web but it's still not working. I am running Windows 7 Professional 64-bit. Here is what I have tried:

(1) I have Python 2.7 and I just installed MinGW with options gcc and g++ and some other options

(2) I edited the PATH environmental variable so it includes

C:\MinGW\bin;C:\MinGW\MSYS\1.0\local\bin;C:\MinGW\MSYS\1.0\bin

(3) I told Python to use MinGW as the default compiler by creating a file named

C:\Python27\Lib\distutils\distutils.cfg, containing

[build]
compiler = mingw32

(I do have MinGW32 by the way)

(4) I removed all instances of -mno-cygwin from the file C:\Python27\Lib\distutils\cygwincompiler.py

(5) I have a file called setup.py and a module called tryingcython.pyx that is written in python. My setup.py says from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext

setup(
    cmdclass = {'build_ext':build_ext},
    ext_modules=[Extension("tryingcython",["tryingcython.pyx"])]
)

So then I open Command Prompt and get into the directory that contains setup.py and tryingcython.pyx, and I type python setup.py build_ext --inplace --compiler=mingw32

Then it tells me:

running build_ext
skipping 'tryingcython.c' Cython extension (up-to-date)
building 'tryingcython.c' extension
gcc -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c tryingcython.c -o build\
temp.win32-2.7\Release\tryingcython.o
error: command 'gcc' failed: No such file or directory

So I guess Cython can't tell that I have gcc and it can't find it or what, even though I've tried about every single piece of advice I can find online for making it realize that I have MinGW which has gcc included. Any help/additional ideas on how I can get cython to actually work would be much appreciated.

1
Have you restarted your session of command prompt? The environment variables aren't updated automatically.IanH
As @IanH said, it does look like gcc.exe is not in your PATH. Can you invoke it directly in your command prompt? (Like C:\> gcc.exe)? In general, I would use a distribution such as Anaconda which comes with all the tools you need to compile a Cython module.joon

1 Answers

0
votes

You are using exactly the same operational system and versions than me.

Try to cal gcc using:

SET input=intput.c
SET output=output.pyd
gcc -shared  -IC:\Python27\include -LC:\Python27\libs -O2 -o %output% %input% -lpython27

Usually I put this call in a cythongcc.bat file, in a directory recognized by the PATH environment variable as:

gcc -shared  -IC:\Python27\include -LC:\Python27\libs -O3 -mtune=native -o %1.pyd %2.c -lpython27

So that I can , from where my cython .pyx files are, just do:

cython input.pyx
cythongcc input input

To get the compiled .pyd working!