Cython ImportError:没有名为并行的模块

发布于 2024-12-19 09:29:44 字数 947 浏览 4 评论 0原文

我正在尝试访问 Cython 0.15 的新并行功能(使用 赛通 0.15.1)。但是,如果我尝试这个最小的示例(testp.py),取自 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

使用此 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})

当我导入 testp 时,Python 告诉我:ImportError:没有名为的模块 并行。事实上,如果我浏览 Cython 包 site-packages,我找不到任何名为的文件或目录 并行。但我认为它应该包含在 发布?有人可以为困惑的用户澄清一下吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里兽 2024-12-26 09:29:44

我正在使用 Cython 0.15+

cython.parallel 存在于 Shadow.py 中:

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

并且 Shadow.py 可以位于 Python 的 dist-packages 目录中,例如 /usr/local/lib/python2 Linux 中的 .6/dist-packages/

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

过气美图社 2024-12-26 09:29:44

您可以使用以下命令在 python 命令行中检查所有 python 模块:

>>> help('modules')

然后尝试使用 easy_install 或 pip 安装/重新安装 cython。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文