系统相关
首页 > 系统相关> > CentOS7服务器安装Python3.9.0

CentOS7服务器安装Python3.9.0

作者:互联网

CentOS版本

[root@izbp1cp2hwkqxg3s2faj1uz ~]# lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 7.8.2003 (Core)
Release:	7.8.2003
Codename:	Core

可以看到我的CentOs核版本是7.8。

节省时间直接跳转方法二


方法一、使用yum包管理器安装

更新环境

为了保证所有环境是最新的状态,先整体更新一下:

yum update -y

安装Python3

yum install -y python3

查看是否安装成功

[root@izbp1cp2hwkqxg3s2faj1uz ~]# python3
Python 3.6.8 (default, Apr  2 2020, 13:34:55) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.

缺点:yum虽然也能安装Python3,但是,不能安装最新版本的Python3.

好处是这种方法不用安装pip3,因为是自带的。

yum卸载python3

yum remove python3

检查是否卸载成功:

[root@izbp1cp2hwkqxg3s2faj1uz ~]# python3
-bash: /usr/bin/python3: No such file or directory

 


方法二、下载编译安装

如果要用最新的python版本,则使用这种方法。

先安装一些依赖的包:

[root@centos7 ~]$ yum install gcc openssl-devel bzip2-devel libffi-devel -y

下载包:

[root@centos7 ~]$ curl -O https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz

注:不同的版本修改版本号3.9.0即可。

提取文件:

[root@centos7 ~]$ tar -zxvf Python-3.9.0.tgz

准备从源代码编译Python:

cd Python-3.9.0 && ./configure prefix=/usr/local/python3

最后使用以下命令完成安装:

make && make install

提示:

  WARNING: The script easy_install-3.9 is installed in '/usr/local/python3/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts pip3 and pip3.9 are installed in '/usr/local/python3/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

提示我们安装的脚本不在路径中,下面创建链接。

创建python3链接:

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

创建pip3链接:

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

验证安装是否成功:

[root@izbp1cp2hwkqxg3s2faj1uz ~]$ python3 --version
Python 3.9.0
[root@izbp1cp2hwkqxg3s2faj1uz ~]$ pip3 --version
pip 20.2.4 from /usr/local/python3/lib/python3.9/site-packages/pip (python 3.9)
[root@izbp1cp2hwkqxg3s2faj1uz ~]$ 

 

标签:bin,CentOS7,yum,usr,服务器,3.9,root,python3,Python3.9
来源: https://www.cnblogs.com/qicaoyu1/p/15521022.html