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