I am trying to run a python (.py) file on a Linux server with Ubuntu. I created a virtual environment with python3.8 -m venv env_name
and installed theano, which is a dependency for the file. I used pip3 install theano=="1.0.5"
while inside the virtual environment and it installed fine. 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.
How do I resolve this error and import theano?
Edit: The entire Traceback of the error message when executing import theano
is:
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. sudo apt-get install python3-dev
on your Ubuntu server to install that and other development header files that theano
needs.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.