Skip to content Skip to sidebar Skip to footer

Cython Memoryviews On Windows

When trying to use Cython on Windows (Anaconda-based install, using TDM-GCC as I need support for OpenMP), I ran into an error when using typed memoryviews. test1.pyx def test(int

Solution 1:

I am using Windows 7 64-bit, Python 2.7.5 64 bit and Cython 0.20.1 and your code works for me.

I tested your original code and this:

deftest(int[:] x):
    s = np.shape(x)[0]
    for i inrange(s):
        print x[i]

without problems. I will describe here how I compiled by Cython and how I configured my C compiler to use with Cython with the hope that you can solve your problem following these steps.

SET DISTUTILS_USE_SDK=1
setenv /x64 /release
  • Compile Cython (simply doing python setup.py should work)

  • Have a nice setup.py for your .pyx files, here it follows a sample that I use to enable support to OpenMP:

from distutils.coreimport setup
from distutils.extensionimportExtensionfromCython.Distutilsimport build_ext
ext_modules = [Extension('test1',
                         ['test1.pyx'],
                         extra_compile_args=['/openmp', '/O2',
                                             '/favor:INTEL64'])]
setup(name = 'test1',
      cmdclass = {'build_ext': build_ext},
      ext_modules = ext_modules)
  • use import pyximport; pyximport.install() when applicable

Solution 2:

As it turns out, the simplest solution was just to switch everything to 32bit, as TDM-GCC 32bit works fine and I don't have any hard dependencies on 64bit-Python.

Post a Comment for "Cython Memoryviews On Windows"