在 cython 文件中导入任何模块会出现未定义的符号错误

Sci*_*pio 5 python numpy cython

当我在用 cython 编译的模块中使用任何import 语句时,我在导入模块时收到以下错误(请参阅下面的完整代码):

ImportError: /.../hw.cpython-35m-x86_64-linux-gnu.so: undefined symbol: __intel_sse2_strchr
Run Code Online (Sandbox Code Playgroud)

在我自己的机器上一切正常,但是当我尝试在外部高性能计算机上重新编译和运行我的脚本时出现此错误。

谷歌搜索我看到在几个地方弹出了类似的错误,但在这些讨论中,问题要么与自己的代码中的错误有关,而不是与导入的模块有关(例如,未定义符号错误导入 Cython 模块)或在构建 cython 或编译时间(例如cython 可以用 icc 编译吗?)。我不知道如何将这些应用于我的案例。

通过阅读其他讨论,我怀疑问题setup.py出在我的 . 我尝试将 numpy 添加到设置中(见setup2.py下文),但这并没有解决问题 - 我在import hw.

完整示例

硬件.pyx:

import numpy  # without this line, the example works fine 

cpdef testfun():
    print("Hello world!")
Run Code Online (Sandbox Code Playgroud)

设置.py:

from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize('hw.pyx'),
)
Run Code Online (Sandbox Code Playgroud)

设置2.py:

from distutils.core import setup
from Cython.Build import cythonize
import numpy as np

setup(
    ext_modules = cythonize('hw.pyx'),
    include_dirs = [np.get_include()]  # -> including this doesn't make a difference
)
Run Code Online (Sandbox Code Playgroud)

系统信息

外部系统运行python 3.5.2。我在 virtualenv 中运行我的代码,在那里我有 Cython 0.28.1。我尝试了 numpy 1.13.0 和 1.14.2。对于本例中的美德环境,我没有安装任何其他包(可能与我的问题无关,但pip freeze也列出了UNKNOWN==0.0.0

[重要编辑]

我收到了 numpy 的错误(因为我之前一直在努力,cdef np.ndarray我认为这是问题所在) - 但实际上是任何导致错误的导入语句 - numpy 恰好是导入的第一个模块。仍然不知道如何解决这个问题。

Sci*_*pio 1

问题是我使用了英特尔编译器,但没有运行英特尔 Python 发行版,或者以其他方式提供英特尔运行时库。

感谢@ead,我通过使用以下命令切换到 GCC 解决了该问题:

CC=gcc python setup.py build_ext --inplace
Run Code Online (Sandbox Code Playgroud)