下载按程序包
编译安装
- 安装编译依赖
yum install -y gcc patch libffi-devel python-devel \ zlib-devel bzip2-devel openssl-devel ncurses-devel \ sqlite-devel readline-devel tk-devel gdbm-devel \ db4-devel libpcap-devel xz-devel
- 解压缩
tar -vxf Python-3.9.8.tgz
- 进入目录
cd Python-3.9.8/
- 指定安装目录生成makefile
./configure
- 编译
make
- 安装
make install
- 完整命令
./configure --prefix=/opt/python398 && make && make install
可能会发生异常
缺少了zlib的解压缩类库,安装
yum -y install zlib*
配置环境
建立软连接
cd /usr/bin
- 创建python3软连接
ln -s /opt/python398/bin/python3.9 python3
- 查看python3版本
[root@bigdata1 bin]# python3 --version Python 3.9.8
- 创建pip3软连接
ln -s /opt/python398/bin/python3.9 python3
- 查看pip版本
[root@bigdata1 bin]# pip3 -V pip 21.2.4 from /opt/python398/lib/python3.9/site-packages/pip (python 3.9)
配置国内源
- 查看当前源地址
[root@bigdata1 bin]# pip3 config list | grep global.index-url
- 设置 pip 为清华源
[root@bigdata1 bin]# pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple Writing to /root/.config/pip/pip.conf
- 再次查看当前源地址
[root@bigdata1 bin]# pip3 config list | grep global.index-url global.index-url='https://pypi.tuna.tsinghua.edu.cn/simple'