IPython module import error: /usr/bin/ld: cannot find -lpython2.7. collect2: ld returned 1 exit status

对着背影说爱祢 提交于 2019-12-23 04:07:12

问题


I'm using the Python module Theano on a server. It is not pre-installed on there so I installed it in my home folder along with some other modules that weren't on the server. I get the following error when I "import theano" in IPython.

Problem occurred during compilation with the command line below:
g++ -shared -g -march=core2 -mcx16 -msahf -maes -mpclmul -mpopcnt -msse4.2 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=12288 -mtune=generic -D NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -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/apps/libs/python/2.7.3/lib/python2.7/site-packages/numpy/core/include -I/home/ext_sxc/include/python2.7 -o /home/ext_sxc/.theano/compiledir_Linux-2.6.32-431.1.2.0.1.el6.x86_64-x86_64-with-centos-6.5-Final-x86_64-2.7.3-64/lazylinker_ext/lazylinker_ext.so /home/ext_sxc/.theano/compiledir_Linux-2.6.32-431.1.2.0.1.el6.x86_64-x86_64-with-centos-6.5-Final-x86_64-2.7.3-64/lazylinker_ext/mod.cpp -L/home/ext_sxc/lib -lpython2.7
/usr/bin/ld: cannot find -lpython2.7
collect2: ld returned 1 exit status

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-1-3397704bd624> in <module>()
----> 1 import theano

/home/ext_sxc/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/__init__.pyc in <module>()
     53     object2, utils
     54
---> 55 from theano.compile import \
     56     SymbolicInput, In, \
     57     SymbolicOutput, Out, \

/home/ext_sxc/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/compile/__init__.py in <module>()
      4         ViewOp, view_op, register_view_op_c_code)
      5
----> 6 from theano.compile.function_module import *
      7
      8 from theano.compile.mode import *

/home/ext_sxc/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/compile/function_module.py in <module>()
     16 from theano import gof
     17 from theano.gof.python25 import partial
---> 18 import theano.compile.mode
     19 from theano.compile.io import In, SymbolicInput, SymbolicInputKit, SymbolicOutput
     20 from theano.compile.ops import deep_copy_op, view_op

/home/ext_sxc/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/compile/mode.py in <module>()
      9 import  theano
     10 from theano import gof
---> 11 import theano.gof.vm
     12 from theano.configparser import config, AddConfigVar, StrParam
     13 from theano.compile.ops import register_view_op_c_code, _output_guard

/home/ext_sxc/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/gof/vm.py in <module>()
    514
    515 try:
--> 516     import lazylinker_c
    517
    518     class CVM(lazylinker_c.CLazyLinker, VM):

/home/ext_sxc/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/gof/lazylinker_c.py in <module>()
     84             args = cmodule.GCC_compiler.compile_args()
     85             cmodule.GCC_compiler.compile_str(dirname, code, location=loc,
---> 86                                              preargs=args)
     87             # Save version into the __init__.py file.
     88             init_py = os.path.join(loc, '__init__.py')

/home/ext_sxc/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/gof/cmodule.pyc in compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module)
   1969             # difficult to read.
   1970             raise Exception('Compilation failed (return status=%s): %s' %
-> 1971                             (status, compile_stderr.replace('\n', '. ')))
   1972         elif config.cmodule.compilation_warning and compile_stderr:
   1973             # Print errors just below the command line.

Exception: Compilation failed (return status=1): /usr/bin/ld: cannot find -lpython2.7. collect2: ld returned 1 exit status.

How can I fix the above error?

Another thing is that whenever I run a Python job on the server, I first do

$ module load libs/python/2.7.3

before executing my Python script and the server has libpython2.6.so in its /usr/lib64 folder. I think this is related to the problem.


回答1:


Your python installation is incomplete. When you do:

module load libs/python/2.7.3

information is added to your environment variables to make you use python 2.7.3. But this version doesn't include the development header of python (Theano needs this). Or it doesn't put the right path in your environment.

To debug this, run this before and after running "module load libs/python/2.7.3" to compare what module load does:

env &> BEFORE.txt
module load libs/python/2.7.3
env &> AFTER.txt
diff BEFORE.txt AFTER.txt

Then check the paths added to your env variables and look in those directories. It should have modified the LD_LIBRARY_PATH variable, but it should have done the same modification to LIBRARY_PATH. If it doesn't, do that modification yourself and tell your system admin about this.

This will solve your problem.

Otherwise, use the python 2.6 from the OS, maybe in include the development version.

Otherwise, check if other python versions are available via module.

Lastly, contact your system admin to add the development and shared version of python or install it yourself:

wget -c http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
tar -jxf Python-2.7.6.tar.bz2 
cd Python-2.7.6
./configure --prefix=~/python2.7.6 --enable-shared
make
make install


来源:https://stackoverflow.com/questions/21644214/ipython-module-import-error-usr-bin-ld-cannot-find-lpython2-7-collect2-ld

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!