[转载]CentOS 7安装Python 2.6(与已有版本共存)
- 安装需要用到的包
[root@hadoop102 ~]# yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget - 下载 Python 2.6.8 版本
[root@hadoop102 ~]# wget https://www.python.org/ftp/python/2.6.8/Python-2.6.8.tgz - 解压文件
[root@hadoop102 ~]# tar -xzvf Python-2.6.8.tgz -C /opt/python/ - 进入解压后文件的目录
[root@hadoop102 ~]# cd Python-2.6.8 - 配置安装信息.
[root@hadoop102 ~]# ./configure --enable-shared --prefix=/opt/module/python2.6 #(添加参数:--enable-shared,这样即会生成libpython2.6.so.1.0) - 编译文件
[root@hadoop102 ~]# make #(若失败提示:configure: error: no acceptable C compiler found in $PATH # 安装GCC:yum install gcc) - 安装编译好的文件
[root@hadoop102 ~]# make altinstall # 使用 altinstall 安装, 不影响其他 Python 版本 - 设置软链接, 方便随时切换 Python 版本
[root@hadoop102 ~]# ln -s /opt/module/python2.6/bin/python2.6 /usr/bin/python2.6 [root@hadoop102 ~]# ln -s /opt/module/python2.6/lib/libpython2.6.so.1.0 /usr/lib/libpython2.6.so.1.0
9.执行python2.6时出现错误:
[root@hadoop102 ~]# python2.6
python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
原因:linux系统默认没有把lib路径加入动态库搜索路径 解决:
[root@hadoop102 ~]# vim /etc/ld.so.conf
# 添加如下一行内容
/opt/module/python2.6/lib #python2.6的路径
[root@hadoop102 ~]# ldconfig # 使新添加的路径生效
[root@hadoop102 ~]# /sbin/ldconfig -v
参考:
- https://www.cnblogs.com/MWCloud/p/11354591.html
- https://blog.csdn.net/lyq19870515/article/details/80449386