CentOS 7安装Python 2.6(与已有版本共存)

1. 安装需要用到的包

yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget

2. 下载 Python 2.6.8 版本

wget https://www.python.org/ftp/python/2.6.8/Python-2.6.8.tgz

3. 解压文件

tar -xzvf Python-2.6.8.tgz -C /opt/software/

4. 进入解压后文件的目录

cd Python-2.6.8

5. 配置安装信息.

./configure  --enable-shared --prefix=/opt/module/python2.6

(添加参数:--enable-shared,这样即会生成libpython2.6.so.1.0)

6. 编译文件

make

(若失败提示:configure: error: no acceptable C compiler found in $PATH

安装GCC:yum install gcc)

7. 安装编译好的文件

make altinstall      # 使用 altinstall 安装, 不影响其他 Python 版本

8. 设置软链接, 方便随时切换 Python 版本

ln -s /opt/module/python2.6/bin/python2.6 /usr/bin/python2.6
ln -s /opt/module/python2.6/lib/libpython2.6.so.1.0  /usr/lib/libpython2.6.so.1.0

9.出现错误:python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

原因:linux系统默认没有把lib路径加入动态库搜索路径 

解决:

[root@hadoop101 ~]# vim /etc/ld.so.conf
# 添加如下一行内容
/opt/module/python2.6/lib  #python2.6的路径
[root@hadoop101 ~]# ldconfig  # 使新添加的路径生效
[root@hadoop101 ~]# /sbin/ldconfig -v

 

参考:https://blog.csdn.net/lyq19870515/article/details/80449386

posted @ 2019-08-14 20:45  猫不夜行  阅读(5135)  评论(0编辑  收藏  举报