python-3.x - 使用 --enable-shared 安装 Python 3 的问题

标签 python-3.x compilation debian mod-wsgi

问题

我正在尝试使用 --enable-shared 选项安装 Python 3。安装“成功”,但生成的 Python 无法运行。安装后尝试运行 Python 会出现以下错误:

$ /opt/python3/bin/python3.5
/opt/python3/bin/python3.5: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory

背景

操作系统是Debian(squeeze),之前安装了Python 2.6,需要保留,因为其他代码依赖它,还有Apache 2.2。最终我想要做的是设置 Django 在 Apache 上运行,这意味着我正在尝试安装需要共享库的 mod_wsgi(或 mod_wsgi-express)。我已经尝试在不使用 --enable-shared 的情况下安装 mod_wsgi在 Python 安装中,并且已经得到......好吧,同样的事情,但这次来自 mod_wsgi 安装程序(以及来自 pip install mod_wsgi ,我也尝试过):/opt/python3/bin/python3.5: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory .

痕迹

中描述的安装开始背景上面,这是我执行的产生上述错误的最小命令列表(删除了详细信息)。
user@server:~$ wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz
user@server:~$ tar -zxvf Python-3.5.1.tgz
user@server:~$ cd Python-3.5.1
user@server:~/Python-3.5.1$ ./configure --prefix=/opt/python3 --enable-shared
user@server:~/Python-3.5.1$ make && sudo make install
(... appears to install correctly)

user@server:~/Python-3.5.1$ /opt/python3/bin/python3.5
/opt/python3/bin/python3.5: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory

我也用 LD_RUN_PATH 试过这个按照此解决方案中的描述设置 other question ,结果相同:
user@server:~/Python-3.5.1$ sudo make distclean
user@server:~/Python-3.5.1$ ./configure --prefix=/opt/python3 --enable-shared
user@server:~/Python-3.5.1$ LD_RUN_PATH=/usr/local/lib make
user@server:~/Python-3.5.1$ sudo make install
user@server:~/Python-3.5.1$ /opt/python3/bin/python3.5
/opt/python3/bin/python3.5: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory

我也用 Python 3.4 尝试过这个,结果相同。我没有在 Python 2 上尝试过这个,因为我不希望 future 的开发仅限于 Python 2.7(因此即使成功安装也无法满足我的要求)。我还假设该尝试不会提供任何新的或有用的信息。

最佳答案

我在 CentOS7 上重复了你的步骤,得到了类似的结果:

$ /tmp/py3/bin/python3
/tmp/py3/bin/python3: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory

如果您查看 python 的链接,它没有提供库的完整路径:
$ ldd /tmp/py3/bin/python3
    linux-vdso.so.1 =>  (0x00007fff47ba5000)
    libpython3.5m.so.1.0 => not found
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fdfaa32e000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007fdfaa12a000)
    libutil.so.1 => /lib64/libutil.so.1 (0x00007fdfa9f27000)
    libm.so.6 => /lib64/libm.so.6 (0x00007fdfa9c24000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fdfa9862000)
    /lib64/ld-linux-x86-64.so.2 (0x000055e85eac5000)

出于某种原因,Python 构建过程没有添加 -rpath到链接行,这将“将目录添加到运行时库搜索路径”。

如果您明确设置库路径,它将起作用:
$ LD_LIBRARY_PATH=/tmp/py3/lib/ /tmp/py3/bin/python3
Python 3.5.1 (default, Jun 10 2016, 14:54:59) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

所以现在问题是你是否想要:
  • 套装LD_LIBRARY_PATH全局在您的系统上
  • 编辑 /etc/ld.so.conf (或 /etc/ld.so.conf.d/*)
  • 使用 chrpath更改嵌入路径
  • export LD_RUN_PATH={prefix}/lib运行前 configuremake (其中 {prefix} 是您传递给 --prefix 的内容。您使用了错误的路径。)
  • 关于python-3.x - 使用 --enable-shared 安装 Python 3 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37757314/

    相关文章:

    linux - 在 debian 系统启动时运行可执行文件

    python - 从 groupby.size() 命令查找总计

    c++ - libtorrent Unresolved external

    mysql - QMSQL : Cannot mix incompatible Qt library (version 0x50b03) with this library (version 0x50c05)

    windows - 在 Windows 上编译基于 Qt 的 NPAPI 浏览器插件

    linux - 我可以运行从更高版本的 gcc 编译的二进制文件吗?

    unix - 在构建 debian 软件包时,lintian 返回missing-dependency-on-libc 时会发生什么

    algorithm - 内存类内部递归函数的深度

    Python - 函数将外部变量设置为用户输入作为副作用

    python - 连接重置错误 : An existing connection was forcibly closed by the remote host