系統(tǒng)環(huán)境:Centos 7.0
- 在不刪除centos自帶的Python2.7情況下 安裝Python3.9
1.安裝編譯相關(guān)工具
- 安裝開發(fā)庫(kù)
yum -y groupinstall "Development tools"
- 安裝依賴環(huán)境
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
yum install libffi-devel -y
2.創(chuàng)建Python文件夾下載安裝包
- 創(chuàng)建存放的文件夾
mkdir /usr/local/python3
- 進(jìn)入存放的文件夾、
cd /usr/local/python3
- 下載Python3.9安裝包
wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
- 解壓
tar.xztar -xvJf Python-3.9.0.tar.xz
3.編譯安裝
- 如果有這兩個(gè)依賴 zlib蝶押、zlib-devel 則不用安裝 沒(méi)有需安裝 否則下面操作會(huì)報(bào)錯(cuò)
yum install zlib zlib
yum install zlib zlib-devel
- 進(jìn)入Python-3.9.0文件夾
cd Python-3.9.0
- 生成makefile文件
./configure prefix=/usr/local/python3 --with-ensurepip=install
- 編譯
make
- 安裝
make install
4.創(chuàng)建軟連接
- 將原有python2鏈接備份
mv /usr/bin/python /usr/bin/python.bak
- 添加python3的軟鏈接
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python
- 查看python版本
python -V
- 更改yum配置寝蹈,因?yàn)槠湟玫絧ython2才能執(zhí)行边翁,否則會(huì)導(dǎo)致yum不能正常使用
vi /usr/bin/yum
原:#! /usr/bin/python 改:#! /usr/bin/python2
vi /usr/libexec/urlgrabber-ext-down
原:#! /usr/bin/python 改:#! /usr/bin/python2
5.驗(yàn)證
- 檢測(cè)python2
python2
- 檢測(cè)python3
python3