我這裏使用的時CentOS7-mini,CentOS系統自己默認安裝有Python2.x,版本x根據不一樣版本系統有所不一樣,可經過 python --V 或 python --version 查看系統自帶的Python版本。html
有一些系統命令時須要用到Python2,不能卸載。python
一、安裝依賴包linux
1)首先安裝gcc編譯器,gcc有些系統版本已經默認安裝,經過 gcc --version 查看,沒安裝的先安裝gcc,yum -y install gccweb
2)安裝其它依賴包,(注:不要缺乏,不然有可能安裝python出錯,python3.7.0如下的版本可不裝 libffi-devel )sql
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel測試
二、下載python3.7.0源碼,根據需求下載.net
1)在https://www.python.org/ftp/python/中選擇本身須要的python源碼包,我下載的是python3.7.0code
yum -y install zlib zlib-devel yum -y install bzip2 bzip2-devel yum -y install ncurses ncurses-devel yum -y install readline readline-devel yum -y install openssl openssl-devel yum -y install openssl-static yum -y install xz lzma xz-devel yum -y install sqlite sqlite-devel yum -y install gdbm gdbm-devel yum -y install tk tk-devel yum -y install libffi libffi-devel
2)下載orm
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgzsqlite
三、解壓Python-3.7.0.tgz
tar -zxvf Python-3.7.0.tgz
四、創建一個空文件夾,用於存放python3程序
mkdir /usr/local/python3
五、執行配置文件,編譯,編譯安裝
cd Python-3.7.0
./configure --prefix=/usr/local/python3
make && make install
安裝完成沒有提示錯誤便安裝成功了
七、創建軟鏈接
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3
八、測試一下python3是否能夠用
[root@mini Python-3.7.0]# python3
Python 3.7.0 (default, Jul 28 2018, 22:47:29)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello world!")
hello world!
>>> exit()
[root@mini Python-3.7.0]# pip3 --version
pip 10.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
能夠看到python3.7.0能夠正常使用
參考: