Python 无法识别 LD_LIBRARY_PATH?

Python 无法识别 LD_LIBRARY_PATH?

我正在尝试以开发人员模式在 cr-48 chromebook 上安装 Python2.7,并面临一个奇怪的问题,我很难在谷歌上搜索解决方案。首先一些背景知识..根分区是只读安装的,所以我一直在 /usr/local 下安装软件包,这是一个可写的单独安装点。有一种方法可以强制根分区本身读写(有一些小缺点),但我决定不走这条路。我一直在下载 archlinux 软件包并将它们解压到 /usr/local 下,其中有几个到目前为止运行良好。我基本上.tar.xz像这样提取文件:

xz -dc package.tar.xz | sudo tar --strip-components=1 -C /usr/local -xvf -

这基本上会将发往 /usr 的文件删除到 /usr/local 下。我/usr/local/lib/usr/lib下提前导出LD_LIBRARY_PATH,并获得了几个可以正常工作的包。由于某种原因,python 无法加载识别这一点,尽管不完全确定是什么原因导致的。扩展我从中获得的 python 2.7 包后archlinux 站点,我能够正常启动 python shell,并且简单的打印工作正常。然后我尝试安装 setuptools,因此从 pypy 下载了源代码并尝试运行sudo /usr/local/python2 setup.py install,但它一直给我以下错误:

/usr/local/bin/python2: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

libpython2.7.so.1.0文件实际上/usr/local/lib/位于LD_LIBRARY_PATH.快速运行 ldd 清楚地表明了这一点:

chronos@localhost /tmp/setuptools-1.1.6 $ ldd /usr/local/bin/python2
        linux-gate.so.1 (0x777a9000)
        libpython2.7.so.1.0 => /usr/local/lib/libpython2.7.so.1.0 (0x77610000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x775ee000)
        libc.so.6 => /lib/libc.so.6 (0x77464000)
        libdl.so.2 => /lib/libdl.so.2 (0x77460000)
        libutil.so.1 => /lib/libutil.so.1 (0x7745b000)
        libm.so.6 => /lib/libm.so.6 (0x77436000)
        /lib/ld-linux.so.2 (0x777aa000)

我也检查过/etc/ld.so.conf,也有/usr/local/lib

chronos@localhost /tmp/setuptools-1.1.6 $ cat /etc/ld.so.conf 
# ld.so.conf autogenerated by env-update; make all changes to
# contents of /etc/env.d directory
/lib
/usr/lib
/usr/local/lib
/usr/lib/opengl/xorg-x11/lib

我安装了strace(并且perl因为它被列为依赖项),并运行了安装命令,strace该命令显示了以下有趣的输出(请注意它不是在寻找/usr/local/lib/libpython2.7.so.1.0任何地方):

chronos@localhost /tmp/setuptools-1.1.6 $ sudo strace /usr/local/bin/python2 setup.py installPassword: 
execve("/usr/local/bin/python2", ["/usr/local/bin/python2", "setup.py", "install"], [/* 16 vars */]) = 0
brk(0)                                  = 0x9b3c000
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x776e6000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=37049, ...}) = 0
mmap2(NULL, 37049, PROT_READ, MAP_PRIVATE, 3, 0) = 0x776dc000
close(3)                                = 0
open("/lib/tls/i686/sse2/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/tls/i686/sse2", 0x7fd88d90) = -1 ENOENT (No such file or directory)
open("/lib/tls/i686/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/tls/i686", 0x7fd88d90)     = -1 ENOENT (No such file or directory)
open("/lib/tls/sse2/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/tls/sse2", 0x7fd88d90)     = -1 ENOENT (No such file or directory)
open("/lib/tls/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/tls", 0x7fd88d90)          = -1 ENOENT (No such file or directory)
open("/lib/i686/sse2/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/i686/sse2", 0x7fd88d90)    = -1 ENOENT (No such file or directory)
open("/lib/i686/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/i686", 0x7fd88d90)         = -1 ENOENT (No such file or directory)
open("/lib/sse2/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/sse2", 0x7fd88d90)         = -1 ENOENT (No such file or directory)
open("/lib/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/usr/lib/tls/i686/sse2/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/tls/i686/sse2", 0x7fd88d90) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/i686/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/tls/i686", 0x7fd88d90) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/sse2/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/tls/sse2", 0x7fd88d90) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/tls", 0x7fd88d90)      = -1 ENOENT (No such file or directory)
open("/usr/lib/i686/sse2/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/i686/sse2", 0x7fd88d90) = -1 ENOENT (No such file or directory)
open("/usr/lib/i686/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/i686", 0x7fd88d90)     = -1 ENOENT (No such file or directory)
open("/usr/lib/sse2/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/sse2", 0x7fd88d90)     = -1 ENOENT (No such file or directory)
open("/usr/lib/libpython2.7.so.1.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/usr/lib", {st_mode=S_IFDIR|0755, st_size=20480, ...}) = 0
writev(2, [{"/usr/local/bin/python2", 22}, {": ", 2}, {"error while loading shared libra"..., 36}, {": ", 2}, {"libpython2.7.so.1.0", 19}, {": ", 2}, {"cannot open shared object file", 30}, {": ", 2}, {"No such file or directory", 25}, {"\n", 1}], 10/usr/local/bin/python2: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
) = 141
exit_group(127)                         = ?
+++ exited with 127 +++

我总是通过包含 lib 路径并将LD_LIBRARY_PATH其导出来获得自定义安装路径,因此不确定这里还可能缺少什么。任何帮助深表感谢。

答案1

除了 之外LD_LIBRARY_PATH,您可能还需要设置一些 Python 特定的环境变量,例如PYTHONHOME& PYTHONPATH。请参阅Python 手册页了解详情。

安装新库后,您可能还需要ldconfig以 root 身份运行来更新库缓存文件。

尝试的另一个选择是设置环境变量RUN_LD_PATH,甚至可能使用-rpath编译-rpath-link器/链接器选项。

您还可以尝试使用prelink下的所有可执行文件和库/usr/local,尽管这可能很乏味,因为目录可能未在 中列出/etc/prelink.conf。也许只是从你的 python 可执行文件开始。

相关内容