[分享栈]centos7安装python3.8.5
1、切换到root账户
2、更新yum源
yum update
中间有询问过程,直接y同意更新就好了。
3、安装依赖项
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel gcc make
4、下载python3.8.5
wget -P /home https://cdn.npm.taobao.org/dist/python/3.8.5/Python-3.8.5.tgz
5、解压
cd /home && tar -zxvf Python-3.8.5.tgz
6、配置编译
cd Python-3.8.5
mkdir /usr/local/python3.8.5
./configure --prefix=/usr/local/python3.8.5
./configure --enable-optimizations
如果出现错误信息:SystemError: <built-in function compile> returned NULL without setting an error generate-posix-vars failed;
则需要升级gcc版本,请先升级gcc版本,参考链接centos7安装gcc10.2.0。
7、编译安装
make && make install
8、建立链接
ln -s /usr/local/python3.8.5/bin/python3 /usr/bin/python3
ln -s /usr/local/python3.8.5/bin/pip3 /usr/bin/pip3
如果提示链接已存在,删除原链接即可。
9、查询版本
python3 --version