Python 2.7 忽略 LD_LIBRARY_PATH

Python 2.7 忽略 LD_LIBRARY_PATH

我正在尝试在没有 root 访问权限的机器上安装 Theano,但LD_LIBRARY_PATH我安装的 Python 2.7 似乎忽略了这一点。由于我无法在系统级别安装软件包,因此我决定从源代码编译所有软件包(Python、SciPy、OpenBLAS 等)并将它们安装到 $HOME。在测试 SciPy 时,我收到错误ERROR: Failure: ImportError (libopenblas.so.0: cannot open shared object file: No such file or directory),但看起来该库存在并且LD_LIBRARY_PATH指向正确的文件夹。这是完整的文字记录:

wheatstone-acogliat 42% echo $LD_LIBRARY_PATH
/home/seas/grad/acogliat/lib

wheatstone-acogliat 43% python -c "import scipy; scipy.test()"
Running unit tests for scipy
NumPy version 1.9.3
NumPy is installed in /home/seas/grad/acogliat/lib/python2.7/site-packages/numpy
SciPy version 0.16.0
SciPy is installed in /home/seas/grad/acogliat/lib/python2.7/site-packages/scipy
Python version 2.7.10 (default, Sep 28 2015, 21:06:05) [GCC 4.1.2 20080704 (Red Hat 4.1.2-55)]
nose version 1.3.7
/home/seas/grad/acogliat/lib/python2.7/site-packages/numpy/lib/utils.py:95: DeprecationWarning: `scipy.weave` is deprecated, use `weave` instead!
  warnings.warn(depdoc, DeprecationWarning)
E.......................................................................K.......................................................................................................EEEEEEEEE.....................................................................................................EE......................................................................S...........EEE...........................................K......................................................................................................
======================================================================
ERROR: Failure: ImportError (libopenblas.so.0: cannot open shared object file: No such file or directory)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/seas/grad/acogliat/lib/python2.7/site-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/home/seas/grad/acogliat/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/home/seas/grad/acogliat/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/home/seas/grad/acogliat/lib/python2.7/site-packages/scipy/cluster/__init__.py", line 27, in <module>
    from . import vq, hierarchy
  File "/home/seas/grad/acogliat/lib/python2.7/site-packages/scipy/cluster/vq.py", line 89, in <module>
    from . import _vq
ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory

[...MULTIPLE SIMILAR ERRORS OMITTED...]

FAILED (KNOWNFAIL=2, SKIP=1, errors=15)

wheatstone-acogliat 44% ls -al $LD_LIBRARY_PATH
total 47232
drwxr-sr-x  6 acogliat eestudent      512 Sep 28 22:58 ./
drwxr-sr-x 19 acogliat eestudent      512 Sep 28 23:29 ../
drwxr-sr-x  3 acogliat eestudent      512 Sep 28 22:58 cmake/
lrwxrwxrwx  1 acogliat eestudent       30 Sep 28 22:58 libopenblas.a -> libopenblas_opteronp-r0.2.14.a
-rw-r--r--  1 acogliat eestudent 25211324 Sep 28 22:57 libopenblas_opteronp-r0.2.14.a
-rwxr-xr-x  1 acogliat eestudent 12826920 Sep 28 22:57 libopenblas_opteronp-r0.2.14.so*
lrwxrwxrwx  1 acogliat eestudent       31 Sep 28 22:58 libopenblas.so -> libopenblas_opteronp-r0.2.14.so*
lrwxrwxrwx  1 acogliat eestudent       31 Sep 28 22:58 libopenblas.so.0 -> libopenblas_opteronp-r0.2.14.so*
-r-xr-xr-x  1 acogliat eestudent 10193546 Sep 28 21:36 libpython2.7.a*
drwxr-sr-x  3 acogliat eestudent      512 Sep 28 22:46 perl5/
drwxr-sr-x  2 acogliat eestudent      512 Sep 28 21:36 pkgconfig/
drwxr-sr-x 28 acogliat eestudent    14336 Sep 28 21:36 python2.7/

wheatstone-acogliat 45% uname -a
Linux wheatstone 2.6.18-404.el5 #1 SMP Tue Apr 7 12:42:54 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux

我缺少什么?

答案1

如果代码显式调用dlopen()来查找文件,它将使用 LD_LIBRARY_PATH,尽管普通的 python 使用$PYTHONPATH来查找模块和库。您还可以设置sys.path数组:

import sys
sys.path.append('/mydir')

请记住导出 LD_LIBRARY_PATH 或 PYTHONPATH。

相关内容