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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM