简体   繁体   English

在ubuntu上导入theano时编译出错

[英]Compilation error when importing theano on ubuntu

I am trying to run a python (.py) file on a Linux server with Ubuntu.我正在尝试在带有 Ubuntu 的 Linux 服务器上运行 python (.py) 文件。 I created a virtual environment with python3.8 -m venv env_name and installed theano, which is a dependency for the file.我使用python3.8 -m venv env_name创建了一个虚拟环境并安装了 theano,这是文件的依赖项。 I used pip3 install theano=="1.0.5" while inside the virtual environment and it installed fine.我在虚拟环境中使用了pip3 install theano=="1.0.5"并且安装得很好。 However, when trying to import the package, I received the following error:但是,在尝试导入包时,我收到以下错误:

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.

The reason I am using theano==1.0.5 is because the code structure I'm using works just fine in Windows 10 with this version and for Python 3.8.我使用theano==1.0.5的原因是因为我使用的代码结构在此版本的 Windows 10 和 Python 3.8 中运行良好。

How do I resolve this error and import theano?如何解决此错误并导入 theano?

Edit: The entire Traceback of the error message when executing import theano is:编辑:执行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.

Your error is saying that theano can't find a version of lazylinker on your system.你的错误是说theano找不到您的系统上一个版本lazylinker的。 sudo apt-get install python3-dev on your Ubuntu server to install that and other development header files that theano needs. sudo apt-get install python3-dev在你的 Ubuntu 服务器上安装theano需要的那个和其他开发头文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM