由於linux自帶的環境是python2,所以python3需要自己安裝
我們使用的是IUS源,IUS(Inline with Upstream Stable)是一個社區項目,它旨在爲Linux企業發行版提供可選軟件的最新版RPM軟件包。 IUS軟件替換CentOS基本源中的軟件使用的是安全替換的方式:即當CentOS系統中安裝了相應的軟件後,再使用IUS源安裝相應的軟件,IUS軟件不會直接更新升級系統自帶的軟件源,而是提示一個衝突,如果要安裝IUS軟件,需要先卸載CentOS系統中自帶的相應的軟件。
此處的linux環境是centos7
[root@Openshift41 ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
安裝EPEL軟件
yum -y install epel-release
安裝IUS軟件源
請根據您的系統選擇rpm包:
https://rhel6.iuscommunity.org/ius-release.rpm
https://rhel7.iuscommunity.org/ius-release.rpm
https://centos6.iuscommunity.org/ius-release.rpm
https://centos7.iuscommunity.org/ius-release.rpm
我的系統是CentOS7,那麼我們選擇CentOS7的源並安裝
yum install https://centos7.iuscommunity.org/ius-release.rpm
安裝完成後進入下一步
安裝python3.6.5
yum -y install python36u python36u-pip
安裝完成後,檢查是否安裝成功
[root@Openshift41 ~]# python3.6
Python 3.6.7 (default, Dec 5 2018, 15:02:05)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
[root@Openshift41 ~]# pip3.6 -V
pip 9.0.1 from /usr/lib/python3.6/site-packages (python 3.6)
建立鏈接
ln -s /bin/python3.6 /bin/python3
ln -s /bin/pip3.6 /bin/pip3
總結
一鍵安裝(centos7)
cat installpy3.sh
#!/bin/bash
echo "install python3 and pip3"
yum install epel-release
yum install https://centos7.iuscommunity.org/ius-release.rpm
yum install python36u # 安裝python
ln -s /bin/python3.6 /bin/python3
yum install python36u-pip # 安裝pip3,相當於linux裏面的yum,可以在線安裝一些python模塊
ln -s /bin/pip3.6 /bin/pip3
echo "done!"