1

我在服务器上使用 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。我认为这与问题有关。

4

1 回答 1

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

然后检查添加到环境变量的路径并查看这些目录。它应该修改了 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
于 2014-02-11T13:23:03.837 回答