使用 --enable-shared 安装 Python 3 的问题 [英] Problems installing Python 3 with --enable-shared
问题描述
我正在尝试使用 --enable-shared 选项安装 Python 3.安装成功",但生成的 Python 无法运行.安装后尝试运行 Python 出现以下错误:
I'm trying to install Python 3 with the --enable-shared option. Installation "succeeds" but the resulting Python is not runnable. Trying to run Python after installation gives the following error:
$ /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 安装程序(来自 pip install mod_wsgi
,我也尝试过):/opt/python3/bin/python3.5:加载共享库时出错:libpython3.5m.so.1.0:无法打开共享对象文件:没有这样的文件或目录
.
Background
The OS is Debian (squeeze), and has a previous installation of Python 2.6, which is necessary to retain because other code relies on it, and Apache 2.2. Ultimately what I'm trying to do is set up Django to run on Apache, meaning I'm trying to install mod_wsgi (or mod_wsgi-express), which requires shared libraries. I have already tried to install mod_wsgi without using --enable-shared
in the Python installation, and have gotten... well, the same thing, but this time from the mod_wsgi installer (and from pip install mod_wsgi
, which I also tried): /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
.
从上面背景中描述的安装开始,这里是我执行的产生上述错误的最少命令列表(删除了详细信息).
Starting from an installation as described in Background above, here is the minimum list of commands I've executed that produce the error above (with verbosity removed).
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
设置,如此 其他问题,结果相同:
I have also tried this with LD_RUN_PATH
set as described in the solution to this other question, with the same results:
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 上尝试过这个,因为我不希望未来的开发仅限于 Python 2.7(因此即使成功安装也无法满足我的要求).我还假设该尝试不会提供任何新的或有用的信息.
I have also tried this with Python 3.4, with the same results. I have not tried this with Python 2, because I do not want future development to be limited to Python 2.7 (therefore even a successful installation would not satisfy my requirements). I'm also assuming the attempt would not provide any new or useful information.
推荐答案
我已经在 CentOS7 上重复了你的步骤并得到了类似的结果:
I've repeated your steps on CentOS7 and get something similar:
$ /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 的链接,它没有提供库的完整路径:
If you look at the linking of python, it isn't providing a full path to the library:
$ 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
添加到链接行,这会向运行时库搜索路径添加目录".
For some reason, the Python build process isn't adding -rpath
to the link line, which would "add a directory to the runtime library search path."
如果您明确设置库路径,它将起作用:
If you explicitly set your library path, it will work:
$ 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.
>>>
所以现在问题是你是否愿意:
So now it becomes a question as to whether you want to:
- 在您的系统上全局设置
LD_LIBRARY_PATH
- 编辑
/etc/ld.so.conf
(或/etc/ld.so.conf.d/*
) - 使用
chrpath
改变嵌入路径 在运行
(其中configure
和make
之前导出 LD_RUN_PATH={prefix}/lib{prefix}
是您传递给--prefix
的内容.您使用了错误的路径.)
- set
LD_LIBRARY_PATH
globally on your system - Edit
/etc/ld.so.conf
(or/etc/ld.so.conf.d/*
) - Use
chrpath
to change the embedded path export LD_RUN_PATH={prefix}/lib
before you runconfigure
andmake
(Where{prefix}
is what you passed to--prefix
. You used the wrong path.)
这篇关于使用 --enable-shared 安装 Python 3 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!