Question

I am trying to access the new parallel features of Cython 0.15 (using Cython 0.15.1). However, if I try this minimal example (testp.py), taken from http://docs.cython.org/src/userguide/parallelism.html:

from cython.parallel import prange, parallel, threadid
cdef int i
cdef int sum = 0

for i in prange(n, nogil=True):
    sum += i
print sum

with this setup.py:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy

ext = Extension("testp", ["testp.pyx"], include_dirs=[numpy.get_include()],
                extra_compile_args=['-fopenmp'], extra_link_args ['-fopenmp'])
setup(ext_modules=[ext], cmdclass={'build_ext': build_ext})

when I import testp, Python tells me: ImportError: No module named parallel. And in fact, if I browse the Cython package in the site-packages, I cannot find any file or directory that is called parallel. But I thought it should be included somewhere in the release? Could someone please clarify for a confused user?

Was it helpful?

Solution

You can check all of your python modules in python command-line using:

>>> help('modules')

And then try to install/reinstall cython using easy_install or pip.

OTHER TIPS

I'm using Cython 0.15+

cython.parallel exists in Shadow.py:

import sys
sys.modules['cython.parallel'] = CythonDotParallel()

And the Shadow.py can be located in your Python's dist-packages directory like /usr/local/lib/python2.6/dist-packages/ in Linux

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top