linux安装Python3

卸载Python3.6

whereis python3 |xargs rm -frv

安装Python3.9
1、安装依赖包
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel -y

2、下载、解压、进入文件
cd /usr/local
wget https://www.python.org/ftp/python/3.9.2/Python-3.9.2.tgz
tar -zxvf Python-3.9.2.tgz
mv Python-3.9.2
cd python3

3、配置路径、编译安装
./configure --prefix=/usr/local/python3
make && make install

4、添加软连接(原来python/pip默认的是2,现在替换成3)
备份:
mv /usr/bin/python /usr/bin/python_back
mv /usr/bin/pip /usr/bin/pip_back
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip

5、加入环境变量
export PATH=$PATH:/usr/local/python3/bin

6、修复 yum 下载(因为 yum 依赖于python2)
vi /usr/libexec/urlgrabber-ext-down
vi /usr/bin/yum
修改首行python为python2

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注