源碼安裝 python3
阿新 • • 發佈:2018-06-06
源碼安裝pythonLinux下默認系統自帶python2.6的版本,這個版本被系統很多程序所依賴,所以不建議刪除,如果使用最新的Python3那麽我們知道編譯安裝源碼包和系統默認包之間是沒有任何影響的,所以可以安裝python3和python2共存
首先去python官網下載python3的源碼包,網址:https://www.python.org/
進去之後點擊導航欄的Downloads,也可以鼠標放到Downloads上彈出菜單選擇Source code,就是源碼包的意思,點進去之後頁面下方可以看到下載鏈接,包括源碼包、Mac OSX安裝包、Windows的安裝包
1 安裝依賴包
[root@node1 ~]# yum -y install wget gcc automake zlib-devel openssl-devel xz [root@node1 ~]# yum install readline-devel.x86_64 #解決python3退格功能
2 編譯安裝
[root@node1 ~]# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
[root@node1 ~]# tar xf Python-3.6.5.tar.xz && cd Python-3.6.5
[root@node1 ~]# ./configure
[root@node1 ~]# make && make install
3 把python3作為默認python
[root@node1 ~]# python --version Python 2.6.6 [root@node1 ~]# which python /usr/bin/python [root@node1 ~]# which python3 /usr/local/bin/python3 [root@node1 ~]# ll /usr/bin/python* -rwxr-xr-x 2 root root 9728 8月 18 2016 /usr/bin/python lrwxrwxrwx 1 root root 6 12月 11 14:14 /usr/bin/python2 -> python -rwxr-xr-x 2 root root 9728 8月 18 2016 /usr/bin/python2.6 [root@node1 ~]# rm -f /usr/bin/python /usr/bin/python2 [root@node1 ~]# ln -s /usr/local/bin/python3 /usr/bin/python [root@node1 ~]# ln -s /usr/bin/python2.6 /usr/bin/python2 驗證: [root@node1 ~]# python --version Python 3.6.5
4 指定yum調用的python版本
4.1 修改/usr/bin/yum
[root@node1 ~]# vim ?/usr/bin/yum
1 #!/usr/bin/python
改為
1 #!/usr/bin/python2.6 # 改為python默認版本,CentOS 7.*為python2.7
或:
[root@node1 ~]# ansible all -m shell -a "sed -i ‘1s#python$#python2.6#g‘ /usr/bin/yum“ [root@node1 ~]# ansible all -m shell -a "head -1 /usr/bin/yum”
修改軟鏈接
[root@node1 ~]# ll /usr/bin/python*
lrwxrwxrwx 1 root root 22 1月 4 09:41 /usr/bin/python -> /usr/local/bin/python3
lrwxrwxrwx 1 root root 18 1月 4 09:41 /usr/bin/python2 -> /usr/bin/python2.6
-rwxr-xr-x 1 root root 9728 8月 18 2016 /usr/bin/python2.6
[root@node1 ~]#
4.2 CentOS 7.*
需要修改 /usr/libexec/urlgrabber-ext-down文件
[root@node1 ~]# ansible all -m shell -a "sed -i ‘1s#python$#python2.7#g‘ /usr/libexec/urlgrabber-ext-down"
[root@node1 ~]# ansible all -m shell -a "head -1 /usr/libexec/urlgrabber-ext-down"
還需要修改/usr/bin/yum-config-manager
[root@node1 ~]# ansible all -m shell -a "sed -i ‘1s#python$#python2.7#g‘ /usr/bin/yum-config-manager"
[root@node1 ~]# ansible all -m shell -a "head -1 /usr/bin/yum-config-manager"
附:
mv /usr/local/lib/{,bak_}libisl.so.10.1.1-gdb.py
提示:Ignoring ensurepip failure: pip 7.1.2 requires SSL/TLS
這是原因沒有安裝或升級openssl:
END
源碼安裝 python3