CentOS 7 安装Python3.6.1 多版本共存

CentOS 7 安装Python3.6.1 多版本共存_第1张图片

下载并编译

wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
tar -zxvf Python-3.6.1.tar.xz
cd Python-3.6
./configure --enable-shared --prefix=/usr/local CFLAGS=-fPIC LDFLAGS="-Wl,-rpath /usr/local/lib"
make -j24
make install

软连接

自3.4版本起,setup_toolspip工具自动安装,所以不用再手动安装了

sudo ln -sf /usr/local/bin/python3.6 /usr/bin/python3
sudo ln -sf /usr/local/bin/python3.6 /usr/bin/python3.6
sudo  ln -sf /usr/local/bin/pip3.6 /usr/bin/pip3
sudo  ln -sf /usr/local/bin/pip3.6 /usr/bin/pip3.6

错误及解决

错误1

[zhangxinming@localhost Python-3.6.1]$ sudo python3
python3: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory
[zhangxinming@localhost Python-3.6.1]$ sudo pip3 install numpy
/usr/local/bin/python3.6: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory

这两类是一个错误,因为库不在pyhon3这个程序可以正确连接的地方。有两种解决方案,一种是在./configure加入LDFLAGS="-Wl,-rpath /usr/local/lib" 手动指定,另一种是设定全局变量LD_LIBRARY_PATH。显然第一种方案更好一些,第二种方案导致普通用户程序感染root程序的执行,危害很大。

你可能感兴趣的:(CentOS 7 安装Python3.6.1 多版本共存)