【vps】Centos 7安装python3.8.5

时间:2022-06-01 22:15:39

【vps】Centos 7安装python3.8.5

前言

由于服务器的搬迁,从香港搬到了大陆,原来的香港服务器即将到期,所以趁着大陆服务器在备案的时候,将新服务器的配置先配置一下。这篇文章就是分享Centos7系统安装python3.8.5

安装编译相关工具

yum -y groupinstall "Development tools"
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
yum install libffi-devel -y

【vps】Centos 7安装python3.8.5

下载python8安装包

wget https://www.python.org/ftp/python/3.8.3/Python-3.8.5.tgz
tar -zxvf Python-3.8.5.tgz

【vps】Centos 7安装python3.8.5

编译安装python3

mkdir /usr/local/python3 #创建编译安装目录
cd Python-3.8.5
./configure --prefix=/usr/local/python3
make && make install

安装之后出现下面两行就成功啦!

Processing /tmp/tmpt63vmht1/setuptools-47.1.0-py3-none-any.whl
Processing /tmp/tmpt63vmht1/pip-20.1.1-py2.py3-none-any.whl
Installing collected packages: setuptools, pip
Successfully installed pip-20.1.1 setuptools-47.1.0

【vps】Centos 7安装python3.8.5

配置软连接

注意:这一步如果原本服务器环境没有python3的软连接,就无需删除,直接ln配置即可

至于我,因为腾讯云的centos自带了python3.6,我嫌版本太低了所以才下的3.8

但是rm -rf删除又很难删除python3.6,索性直接把软连接给3.8

首先删除原本的python3软连接

rm /usr/bin/python3

然后再建个新的软连接

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

【vps】Centos 7安装python3.8.5

到此python3.8.5可以完美运行了

但是追求卓越的我也想把pip3的软连接换了

rm /usr/bin/pip3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

【vps】Centos 7安装python3.8.5

还有注意不要把python的软连接给python3,因为python默认软连是python2,而centos的yum指令是由python2执行的,所以不要轻易改变!