Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.4: compile cython module for 64-bit windows

I have a .pyx module that I've been trying to compile for use with 64-bit python 3.4 on Windows through various means but with no success.

After a lot of trial and error, it does compile with

python setup.py build_ext --inplace --compiler=mingw32

but of course, that won't work with 64-bit python.

With msvc as the compiler, the error is

File "C:\Python34\lib\distutils\msvc9compiler.py", line 287, in query_vcvarsall
raise ValueError(str(list(result.keys())))
ValueError: ['path']
  • Windows 7
  • Microsoft Windows SDK for Windows 7 and .NET Framework 4 installed
  • There appears to be some Microsoft Visual Studio 10.0 stuff in C:\Program Files (x86) (including vcvarsall.bat)

Solutions that don't revolve around distutils are also welcome.

--- EDIT: Additional information

I have now modified distutils to recognize mingw-w64 as per http://bugs.python.org/issue11723. I then made libpython34.a using gendef and dlltool, but get an error

c:\Python34\libs/libpython34.a: file not recongnized: File truncated

when running

python setup.py build_ext --inplace --compiler=mingw64
like image 579
sjp Avatar asked Dec 15 '14 16:12

sjp


People also ask

Does Cython work on Windows?

MSVC is the only compiler that Cython is currently tested with on Windows. A possible alternative is the open source MinGW (a Windows distribution of gcc). See the appendix for instructions for setting up MinGW manually.


1 Answers

Ok, at long last I managed to make it work.

The fantastic resources by Christoph Gohlke (http://www.lfd.uci.edu/~gohlke/pythonlibs) are key.

  1. Install your desired Python version in the conventional way
  2. Install any extensions you need from Gohlke's site
  3. Install MinGW-w64 from http://tdm-gcc.tdragon.net/download
  4. Patch distutils as per http://bugs.python.org/issue11723
  5. Install the appropriate version of libpython from Gohlke's site
  6. Bob's yer uncle

(Trying all sorts of wild suggestions for this task, I have gone through many more steps but as far as I can tell, these are the only ones that actually made a difference in the end)

like image 63
sjp Avatar answered Oct 22 '22 19:10

sjp