使用--enable-shared安装Python 3时出现问题

时间:2016-06-10 21:19:15

标签: 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),这需要共享库。我已经尝试在Python安装中使用--enable-shared在没有的情况下安装mod_wsgi ,并且得到了......好吧,同样的事情,但这次来自mod_wsgi安装程序(以及来自{{ 1}},我也尝试过):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

我也尝试使用此other question解决方案中所述的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

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

2 个答案:

答案 0 :(得分:5)

我已经在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}/libconfigure之前
  • make  {prefix}是您传递给--prefix的地方。您使用了错误的路径。)

答案 1 :(得分:2)