CentOS7.7安装python3.8.2并升级pip至20
1.安装第三方库
# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make # yum install libffi-devel -y
2.下载与安装python3
# 建立新目录 # sudo mkdir /usr/local/python3 # 下载安装包 # wget --no-check-certificate https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz # 解压安装包 # tar xzvf Python-3.8.2.tgz # cd Python-3.8.2 # 编译安装 # sudo ./configure --prefix=/usr/local/python3
# sudo make
# sudo make install
3、修改系统的默认Python编译器
# 删除默认Python软连接 # rm /usr/bin/python # 创建软链接 # sudo ln -s /usr/local/python3/bin/python3 /usr/bin/python
4.验证python安装
# python -V
5.用python升级pip
# python -m pip install --upgrade pip
6、测试安装
# pip -V
7、修改.bashrc文件添加PATH环境变量
# vim ~/.bashrc
在内容中最后一行添上:
# export PATH=/usr/local/python3/bin/:$PATH
使环境变量配置生效方法有两种:
(1)关闭当前终端窗口,重新打开一个新终端窗口就能生效
(2)输入“source ~/.bashrc”命令,立即生效
8、编辑yum文件以解决yum报错
# vim /usr/bin/yum
将yum文件内容中第一行的#!/usr/bin/python2 改为:
#!/usr/bin/python2.7
若yum update在执行过程报错,需要将 /usr/libexec/urlgrabber-ext-down 文件的第一行也改为 #!/usr/bin/python2.7
转载请注明出处。