gpt4 book ai didi

python - 在 ubuntu 上导入 theano 时出现编译错误

转载 作者:行者123 更新时间:2023-12-04 18:48:45 33 4
gpt4 key购买 nike

我正在尝试在带有 Ubuntu 的 Linux 服务器上运行 python (.py) 文件。我用 python3.8 -m venv env_name 创建了一个虚拟环境并安装了theano,这是该文件的依赖项。我用了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 中运行良好。
如何解决此错误并导入 theano?
编辑:
执行 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在您的系统上找不到lazylinker 的版本。 sudo apt-get install python3-dev在您的 Ubuntu 服务器上安装 theano 的那个和其他开发头文件需要。

关于python - 在 ubuntu 上导入 theano 时出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68216536/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com