下载源码包
wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
tar -zxvf Python-3.9.0.tgz
cd Python-3.9.0
安装系统依赖(重要)
这一步不执行,后面各种错误,报错后,从这一步从新开始。
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 python3-devel libffi-devel
编译安装
指定安装目录为/opt/python39
./configure --prefix=/opt/python39
make && make install
修改环境变量
追加到PATH中
vim /etc/profile
export PATH=/opt/python39/bin:$PATH
激活
source /etc/profile
版本号验证
python3 --verson
pip3 --version
设置代理
国外的镜像比较慢,可以设置镜像来安装。
http://pypi.douban.com/simple/ 豆瓣
http://mirrors.aliyun.com/pypi/simple/ 阿里
http://pypi.hustunique.com/simple/ 华中理工大学
http://pypi.sdutlinux.org/simple/ 山东理工大学
http://pypi.mirrors.ustc.edu.cn/simple/ 中国科学技术大学
https://pypi.tuna.tsinghua.edu.cn/simple 清华
项目中安装依赖
pip install <packageName> -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip3 install -r ./requirements.txt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com