导入cython文件中的任何模块会产生未定义的符号错误

时间:2022-12-12 20:52:05

When I use any import statement within modules I compile with cython, I receive the following error on importing the modules (see full code below):

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

ImportError: /.../hw.cpython-35m-x86_64-linux-gnu.so: undefined symbol: __intel_sse2_strchr

Everything works fine on my own machine, but I get this error when trying to recompile and run my scripts on an external high-performance computer.

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

Googling I saw similar errors pop up in several places, but in these discussions the problem is either related to an error in the own code, rather than an imported module (e.g. Undefined symbol error importing Cython module) or something goes wrong at building cython or compile time (e.g. Can cython be compiled with icc?). I don't see how to apply these to my case.

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

From reading other discussions, I suspected the problem was in the formulation of my setup.py, but I really don't know much about that - on my own system the standard examples simply worked. I tried adding numpy to the setup (see setup2.py below), but that didn't solve the problem - I get the same error on import hw.

通过阅读其他讨论,我怀疑问题在于我的setup.py的制定,但我真的不太了解 - 在我自己的系统上,标准的例子简单有效。我尝试将numpy添加到设置中(请参阅下面的setup2.py),但这并没有解决问题 - 我在导入hw时得到了相同的错误。

Full example

hw.pyx:

import numpy  # without this line, the example works fine 

cpdef testfun():
    print("Hello world!")

setup.py:

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

setup(
    ext_modules = cythonize('hw.pyx'),
)

setup2.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
)

System info

The external system runs python 3.5.2. I run my code within a virtualenv, where I have Cython 0.28.1. I tried both numpy 1.13.0 and 1.14.2. For the virtuel environment in this example, I did not install any other packages (probably not related to my problem, but pip freeze also lists UNKNOWN==0.0.0)

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

[IMPORTANT EDIT]

I received the error for numpy (and since I had struggled before with cdef np.ndarray I figured that was the problem) - but actually it is any import statement that causes the error - numpy just happened to be the first module that was imported. Still no clue how to resolve this though.

我收到numpy的错误(因为我之前用cdef np.ndarray挣扎过去,我认为这是问题) - 但实际上它是导致错误的任何import语句 - numpy恰好是导入的第一个模块。仍然不知道如何解决这个问题。

1 个解决方案

#1


0  

The problem was that I used the Intel compiler without running the Intel Python distribution, or otherwise providing the Intel runtime libraries.

问题是我使用英特尔编译器而没有运行英特尔Python发行版,或者提供英特尔运行时库。

Thanks to @ead, I resolved the problem by switching to GCC using:

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

CC=gcc python setup.py build_ext --inplace

#1


0  

The problem was that I used the Intel compiler without running the Intel Python distribution, or otherwise providing the Intel runtime libraries.

问题是我使用英特尔编译器而没有运行英特尔Python发行版,或者提供英特尔运行时库。

Thanks to @ead, I resolved the problem by switching to GCC using:

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

CC=gcc python setup.py build_ext --inplace