在ubuntu上导入teano时发生编译错误



我正试图用Ubuntu在Linux服务器上运行一个python(.py(文件。我用python3.8 -m venv env_name创建了一个虚拟环境,并安装了no,这是该文件的一个依赖项。我在虚拟环境中使用了pip3 install theano=="1.0.5",它安装得很好。然而,在尝试导入包时,我收到了以下错误:

raise Exception('Compilation failed (return status=%s): %s' %
Exception: Compilation failed (return status=1): /usr/bin/ld: /usr/local/lib/libpython3.8.a(abstract.o): relocation R_X86_64_PC32 against symbol `PyObject_SetItem' can not be used when making a shared object; recompile with -fPIC. /usr/bin/ld: final link failed: Bad value. collect2: error: ld returned 1 exit status.

我之所以使用theano==1.0.5,是因为我使用的代码结构在这个版本的Windows 10和Python 3.8中运行得很好。

如何解决此错误并导入该o?

编辑:执行import theano时错误消息的整个Traceback是:

Traceback (most recent call last):
File "/home/Automatizacao/vxdex/vxdex_env/lib/python3.8/site-packages/theano/gof/lazylinker_c.py", line 76, in <module>
raise ImportError(
ImportError: Version check of the existing lazylinker compiled file. Looking for version 0.211, but found None. Extra debug information: force_compile=False, _need_reload=True
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/Automatizacao/vxdex/vxdex_env/lib/python3.8/site-packages/theano/gof/lazylinker_c.py", line 99, in <module>
raise ImportError(
ImportError: Version check of the existing lazylinker compiled file. Looking for version 0.211, but found None. Extra debug information: force_compile=False, _need_reload=True
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/Automatizacao/vxdex/vxdex_env/lib/python3.8/site-packages/theano/__init__.py", line 110, in <module>
from theano.compile import (
File "/home/Automatizacao/vxdex/vxdex_env/lib/python3.8/site-packages/theano/compile/__init__.py", line 12, in <module>
from theano.compile.mode import *
File "/home/Automatizacao/vxdex/vxdex_env/lib/python3.8/site-packages/theano/compile/mode.py", line 11, in <module>
import theano.gof.vm
File "/home/Automatizacao/vxdex/vxdex_env/lib/python3.8/site-packages/theano/gof/vm.py", line 674, in <module>
from . import lazylinker_c
File "/home/Automatizacao/vxdex/vxdex_env/lib/python3.8/site-packages/theano/gof/lazylinker_c.py", line 139, in <module>
cmodule.GCC_compiler.compile_str(dirname, code, location=loc,
File "/home/Automatizacao/vxdex/vxdex_env/lib/python3.8/site-packages/theano/gof/cmodule.py", line 2410, in compile_str
raise Exception('Compilation failed (return status=%s): %s' %
Exception: Compilation failed (return status=1): /usr/bin/ld: /usr/local/lib/libpython3.8.a(abstract.o): relocation R_X86_64_PC32 against symbol `PyObject_SetItem' can not be used when making a shared object; recompile with -fPIC. /usr/bin/ld: final link failed: Bad value. collect2: error: ld returned 1 exit status.

您的错误是说theano在您的系统上找不到lazyliner的版本。在Ubuntu服务器上安装sudo apt-get install python3-dev,以安装theano所需的开发头文件和其他头文件。

相关内容

  • 没有找到相关文章

最新更新