Linux 安装Python3.7

python

系统为Centos7.8,默认已经安装了Python2.7.5。
Python3和Python2可以共存,安装Python3不要卸载Python2,因为yum依赖于Python2。

刚开始不清楚,按照网上教程删除了Python2和yum。
1、删除现有Python

rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps

whereis python |xargs rm -frv

whereis python

2、删除现有的yum

rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps

whereis yum |xargs rm -frv

结果发现后面安装Python3需要yum,于是只能重装Python2和yum

1、查看本机CentOS版本

cat /etc/redhat-release

结果:CentOS Linux release 7.8.2003 (Core)

2、创建python和yum两个文件夹

mkdir /usr/local/src/python

mkdir /usr/local/src/yum

3、根据上面版本7.8.2003

访问:https://vault.centos.org/7.8.2003/os/x86_64/Packages/
下载下面文件,放到/usr/local/src/python:

dbus-python-devel-1.1.1-9.el7.x86_64.rpm

python-2.7.5-88.el7.x86_64.rpm

python-iniparse-0.4-9.el7.noarch.rpm

python-libs-2.7.5-88.el7.x86_64.rpm

python-pycurl-7.19.0-19.el7.x86_64.rpm

python-urlgrabber-3.10-10.el7.noarch.rpm

rpm-python-4.11.3-43.el7.x86_64.rpm

下载下面文件,放到/usr/local/src/yum

yum-3.4.3-167.el7.centos.noarch.rpm

yum-metadata-parser-1.1.4-10.el7.x86_64.rpm

yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm

4、安装python

cd /usr/local/src/python

rpm -ivh python-* rpm-python-*

如果出现安装包依赖问题,执行

rpm -ivh python-* rpm-python-* --nodeps --force

5、安装yum

cd /usr/local/src/yum

rpm -ivh yum-*

安装Python3.7

1.安装编译工具和依赖环境等

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

2.下载Python3安装包、解压

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz

tar -zxvf Python-3.7.0.tar.xz

3.编译安装

mkdir /usr/local/python3

cd Python-3.7.0

./configure --prefix=/usr/local/python3

make && make install

4.建立软连接

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

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

5.验证是否成功

python3 -V

pip3 -V

以上是 Linux 安装Python3.7 的全部内容, 来源链接: utcz.com/z/388940.html

回到顶部