使用/ openmp编译的模块无法导入?

时间:2012-08-02 13:47:50

标签: python python-2.7 openmp cython

我有一个非常简单的cython代码,它使用prange,在linux中工作正常。但是,当我尝试在Windows中执行此操作时。我遇到了一个问题,它可以编译但无法导入:

ImportError: DLL load failed: This application has failed to start because the a
pplication configuration is incorrect. Reinstalling the application may fix this
problem.

此外,在Windows中我不能from cython.parallel import threadlocal ?!奇怪...

有没有人可以指明方向?

系统工作正常: linux64 ,编译器 gcc ,包: Python 2.7,cython 0.16

系统有问题: Win64 ,编译器: MSVC VS2008 ,包: Python 2.7,cython 0.16

这是我简单的cython pyx:

cimport cython
from cython.parallel import prange

def f(int n):
    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 as np


setup(
    cmdclass = {'build_ext': build_ext},
    include_dirs = [np.get_include()], 
    ext_modules = [Extension("pcython1",  ["pcython1.pyx"],extra_compile_args=['/openmp',],),]
)

2 个答案:

答案 0 :(得分:1)

由于VS2008安装程序错误,amd64_microsoft.vc90.openMP未安装到winSxS中。安装openMP运行时将解决此问题。

详细信息请参阅此问题:How to properly setup VS2008 for x64 programing?

答案 1 :(得分:0)

使用MinGW(请参阅this question正确设置mingw with cython),然后将 setup.py 更新为:

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

ext_modules = [Extension("convolve_cy", ["convolve_cy.pyx"],
                         extra_compile_args = ["-O3", "-fopenmp"],
                         extra_link_args=["-fopenmp"])]

setup (
    name = 'performance test app',
    cmdclass = {'build_ext': build_ext},
    include_dirs = [np.get_include()],
    ext_modules = ext_modules,
)

这是在使用Python 2.7和cython 2.0的windows7多核64位机器上工作。

相关问题