IPython模块导入错误:/ usr / bin / ld:找不到-lpython2.7。 collect2:ld返回1退出状态

时间:2014-02-08 09:19:05

标签: python theano

我在服务器上使用Python模块Theano。它没有预先安装在那里,所以我将它安装在我的主文件夹中,以及一些不在服务器上的其他模块。当我在IPython中“导入theano”时出现以下错误。

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.

如何修复上述错误?

另一件事是,无论何时我在服务器上运行Python作业,我都会先做

$ module load libs/python/2.7.3

在执行我的Python脚本之前,服务器在/ usr / lib64文件夹中有libpython2.6.so。我认为这与问题有关。

1 个答案:

答案 0 :(得分:0)

您的python安装不完整。当你这样做时:

module load libs/python/2.7.3

信息被添加到您的环境变量中以使您使用python 2.7.3。但是这个版本不包含python的开发头(Theano需要这个)。或者它没有在您的环境中放置正确的路径。

要调试它,在运行“module load libs / python / 2.7.3”之前和之后运行它来比较模块加载的作用:

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

然后检查添加到env变量的路径并查看这些目录。它应该修改了LD_LIBRARY_PATH变量,但它应该对LIBRARY_PATH进行相同的修改。如果没有,请自行修改,并告诉系统管理员。

这将解决您的问题。

否则,请使用操作系统中的python 2.6,可能包含开发版本。

否则,检查是否有其他python版本可通过模块。

最后,请与您的系统管理员联系以添加python的开发和共享版本或自行安装:

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