2014-01-24 7 views
11

Nach der Installation von Python, numpy, scipy und Theano zu ~/.local, habe ich versucht, Theano zu importieren, aber es warf einen Fehler:Fehler beim Importieren Theano

>>> import theano 
Problem occurred during compilation with the command line below: 
g++ -shared -g -march=core2 -mcx16 -msahf --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=4096 -mtune=core2 -D NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -D NPY_ARRAY_ENSUREARRAY=NPY_ENSUREARRAY -D NPY_ARRAY_ENSURECOPY=NPY_ENSURECOPY -D NPY_ARRAY_ALIGNED=NPY_ALIGNED -D NPY_ARRAY_WRITEABLE=NPY_WRITEABLE -D NPY_ARRAY_UPDATE_ALL=NPY_UPDATE_ALL -D NPY_ARRAY_C_CONTIGUOUS=NPY_C_CONTIGUOUS -D NPY_ARRAY_F_CONTIGUOUS=NPY_F_CONTIGUOUS -m64 -fPIC -I/opt/python/lib/python2.7/site-packages/numpy/core/include -I/home/minh.lengoc/.local/include/python2.7 -o /home/minh.lengoc/.theano/compiledir_Linux-2.6.32-279.14.1.el6.x86_64-x86_64-with-centos-6.3-Final-x86_64-2.7.6-64/lazylinker_ext/lazylinker_ext.so /home/minh.lengoc/.theano/compiledir_Linux-2.6.32-279.14.1.el6.x86_64-x86_64-with-centos-6.3-Final-x86_64-2.7.6-64/lazylinker_ext/mod.cpp -L/home/minh.lengoc/.local/lib -lpython2.7 
/usr/bin/ld: /home/minh.lengoc/.local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC 
/home/minh.lengoc/.local/lib/libpython2.7.a: could not read symbols: Bad value 
collect2: ld returned 1 exit status 

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/home/minh.lengoc/setup/Theano/theano/__init__.py", line 55, in <module> 
    from theano.compile import \ 
    File "/home/minh.lengoc/setup/Theano/theano/compile/__init__.py", line 6, in <module> 
    from theano.compile.function_module import * 
    File "/home/minh.lengoc/setup/Theano/theano/compile/function_module.py", line 18, in <module> 
    import theano.compile.mode 
    File "/home/minh.lengoc/setup/Theano/theano/compile/mode.py", line 11, in <module> 
    import theano.gof.vm 
    File "/home/minh.lengoc/setup/Theano/theano/gof/vm.py", line 516, in <module> 
    import lazylinker_c 
    File "/home/minh.lengoc/setup/Theano/theano/gof/lazylinker_c.py", line 86, in <module> 
    preargs=args) 
    File "/home/minh.lengoc/setup/Theano/theano/gof/cmodule.py", line 1975, in compile_str 
    (status, compile_stderr.replace('\n', '. '))) 
Exception: Compilation failed (return status=1): /usr/bin/ld: /home/minh.lengoc/.local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC. /home/minh.lengoc/.local/lib/libpython2.7.a: could not read symbols: Bad value. collect2: ld returned 1 exit status. 

ich auf einem Red Hat Box bin installieren:

$ cat /proc/version 
Linux version 2.6.32-279.14.1.el6.x86_64 ([email protected]) (gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC)) #1 SMP Tue Nov 6 23:43:09 UTC 2012 

Was soll ich tun ...?

Antwort

17

Sie haben Python nicht korrekt erstellt. Es wurde nicht mit dem Parameter -fPIC kompiliert. Sehen Sie sich an, wie Sie Python mit einer gemeinsam genutzten Bibliothek kompilieren.

EDIT: Sie müssen Python wie folgt kompilieren:

./configure --enable-shared 
make 
make install 
+0

Vielen Dank! Ich musste auch 'export LD_LIBRARY_PATH =/home/minh.lengoc/.local/lib: $ LD_LIBRARY_PATH' ausführen, damit es funktioniert. –

+0

@ ngọcminh.oss: Was ist in Ihrem lib-Verzeichnis, das Sie zum LD_LIBRARY_PATH hinzufügen mussten? – hlin117

+0

Nevermind, fand die Antwort hier: http://stackoverflow.com/questions/7880454/python-executable-not-finding-libpython-shared-library – hlin117

0

ich virtualenv auf Ubuntu 16.04, verwendet und vor Python mit pyenv install 3.6.1 Ich lief Python den folgenden Befehl ein, um sicherzustellen, mit der fPIC Flagge Installation wird gebaut :

export CONFIGURE_OPTS="OPT=\"-fPIC\"" 

Dann konnte ich Theano ordnungsgemäß installieren und ausführen.