Centos安装Python3.8.2-最新稳定版
注* 以下安装环境为 centos, 默认root权限下进行的安装
升级宝塔自带的python2.7.5到3.8.2
一.安装基础库
1.更新yum源
yum -y update
2.安装EPEL扩展,PIP 安装依赖 epel-release 库
yum -y install epel-release
当遇到SSL问题 ‘pip is configured with locations that require TLS/SSL’,说明openssl-devel未在系统安装
3.一下库建议全部安装
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel
4.gcc, c++, kernel-devel
yum -y install gcc gcc-c++ kernel-devel
5.python源码包下载,国内网络可能需要1分钟
wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz
二.解压源码包
tar -zxvf Python-3.8.2.tgz
三.配置安装路径,目录授权
cd /usr/local/
mkdir python3
chmod 777 python3/
四.关联安装,编译,安装
cd Python-3.8.2
./configure --prefix=/usr/local/python3
make all & make install
五.查看安装是否完成
ll /usr/local/python3/bin/
六.软连接替换
1.旧版本备份
mv /usr/bin/python /usr/bin/python2.x
2.软连接新的python
ln -s /usr/local/python3/bin/python3 /usr/bin/python -f
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip -f
七.centos yum配置和install 配置文件更新
由于yum安装时使用的python2.x的版本,使用了python3.x的版本会导致yum执行安装时不能正常安装,出现报错
vi /usr/bin/yum
注释:#!/usr/bin/python
修改为:#!/usr/bin/python2.x
八.更改pip源
mkdir ~/.pip
cd ~/.pip && touch pip.conf
vi pip.conf
[global]
index-url = http://pypi.douban.com/simple
[install]
use-mirrors =true
mirrors =http://pypi.douban.com/simple/
trusted-host =pypi.douban.com
九.pip 升级
pip install --upgrade pip