问题描述

系统可能携带的是python3.6,而自动化开发基线是python3.7就会导致部分包无法使用等问题

升级python3.7

  1. 查看当前系统python版本
ls -al /usr/bin |grep python

输出:

[uos@localhost ~]$ ls -al /usr/bin |grep python
lrwxrwxrwx  1 root root          31 11月 30  2021 python3 -> /usr/libexec/platform-python3.6
lrwxrwxrwx  1 root root          32 11月 30  2021 python3.6m -> /usr/libexec/platform-python3.6m
lrwxrwxrwx  1 root root          25  2月 20 09:54 python3.bak -> /etc/alternatives/python3
lrwxrwxrwx  1 root root          24  2月 20 09:54 unversioned-python -> /etc/alternatives/python

基本说明python3版本是python3.6了

  1. 下载目标版本python3.7 tar包
    官方地址找到你要升级的版本点击download ,鼠标往下拉,找到 Files:

Files

Version

Operating System

Description

MD5 Sum

File Size

GPG

Gzipped source tarball

Source release

2ee10f25e3d1b14215d56c3882486fcf

22973527

SIG

XZ compressed source tarball

Source release

93df27aec0cd18d6d42173e601ffbbfd

17108364

SIG

macOS 64-bit/32-bit installer

macOS

for Mac OS X 10.6 and later

5a95572715e0d600de28d6232c656954

34479513

SIG

macOS 64-bit installer

macOS

for OS X 10.9 and later

4ca0e30f48be690bfe80111daee9509a

27839889

SIG

Windows help file

Windows

7740b11d249bca16364f4a45b40c5676

8090273

SIG

Windows x86-64 embeddable zip file

Windows

for AMD64/EM64T/x64

854ac011983b4c799379a3baa3a040ec

7018568

SIG

Windows x86-64 executable installer

Windows

for AMD64/EM64T/x64

a2b79563476e9aa47f11899a53349383

26190920

SIG

Windows x86-64 web-based installer

Windows

for AMD64/EM64T/x64

047d19d2569c963b8253a9b2e52395ef

1362888

SIG

Windows x86 embeddable zip file

Windows

70df01e7b0c1b7042aabb5a3c1e2fbd5

6526486

SIG

Windows x86 executable installer

Windows

ebf1644cdc1eeeebacc92afa949cfc01

25424128

SIG

Windows x86 web-based installer

Windows

d3944e218a45d982f0abcd93b151273a

1324632

SIG

选择第一个 Gzipped source tarball 点击下载到本机

  1. 解压tar包(我这里下载了高版本3.9)
[uos@localhost Desktop]$ tar -zxvf Python-3.9.6.tgz

在当前目录会出现一个Python-3.9.6目录,进入该目录

[uos@localhost Desktop]$ cd Python-3.9.6/

在当前目录执行:

[uos@localhost Python-3.9.6]$ ./configure
  1. 安装一些编译依赖,直接切换到root用户执行
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
  1. 开始编译:
[uos@localhost Python-3.9.6]$ make
  1. 开始安装
[uos@localhost Python-3.9.6]$ make install
  1. 这个时候直接执行python3,可能就已经是python3.9版本了(目前我的就是),如果还是python3.6继续第8步
  2. 修改/usr/bin/python3 指向的软连接到第三步解压出来的python先删除或者重命名原来的/usr/bin/python3
[root@localhost Python-3.9.6]# mv /usr/bin/python3 /usr/bin/python3.bak

新建/usr/bin/python3软连接

[root@localhost Python-3.9.6]# ln -s /home/uos/Desktop/Python-3.9.6/python /usr/bin/python3

查看一下:

[root@localhost bin]# ls -al |grep python
lrwxrwxrwx  1 root root          37  2月 20 18:36 python3 -> /home/uos/Desktop/Python-3.9.6/python
lrwxrwxrwx  1 root root          31 11月 30  2021 python3.6 -> /usr/libexec/platform-python3.6
lrwxrwxrwx  1 root root          32 11月 30  2021 python3.6m -> /usr/libexec/platform-python3.6m
lrwxrwxrwx  1 root root          25  2月 20 09:54 python3.bak -> /etc/alternatives/python3
lrwxrwxrwx  1 root root          29  2月 20 18:04 python3.bak1 -> /home/uos/Python-3.9.6/python
lrwxrwxrwx  1 root root          24  2月 20 09:54 unversioned-python -> /etc/alternatives/python

执行一下python3

[root@localhost bin]# python3
Python 3.9.6 (default, Feb 20 2023, 17:52:09) 
[GCC 8.5.0 20210514 (UnionTech 8.5.0-10.0.3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>