Linux-学习-06-Python3安装与卸载

目录

一、环境信息

二、卸载Python3

1、使用包管理器卸载

2、手动卸载

三、安装Python3

 1、下载Python3

(1)下载地址

(2)版本

2、解压

3、切换目录

4、配置

5、编译

(1)报错:Could not build the ssl module!

(2)安装OpenSSL 1.1.1

(3)安装开发工具和库

6、编译安装

7、创建软连接

8、验证


一、环境信息

名称
CPUIntel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
操作系统CentOS Linux release 7.9.2009 (Core)
内存4G
逻辑核数4
原Python3版本3.6.8
新Python3版本3.12.4

二、卸载Python3

1、使用包管理器卸载

[root@czg0 openssl-1.1.1w]# yum remove python3

2、手动卸载

[root@czg0 GcdwPkg]# whereis python3
python3: /usr/bin/python3 /usr/bin/python3.6 /usr/bin/python3.6m /usr/bin/python3.6-config /usr/bin/python3.6m-config /usr/bin/python3.6m-x86_64-config /usr/lib/python3.6 /usr/lib64/python3.6 /usr/local/lib/python3.6 /usr/include/python3.6m /usr/share/man/man1/python3.1.gz

[root@czg0 GcdwPkg]# rm -rf /usr/bin/python3 /usr/bin/python3.6 /usr/bin/python3.6m /usr/bin/python3.6-config /usr/bin/python3.6m-config /usr/bin/python3.6m-x86_64-config /usr/lib/python3.6 /usr/lib64/python3.6 /usr/local/lib/python3.6 /usr/include/python3.6m /usr/share/man/man1/python3.1.gz

三、安装Python3

 1、下载Python3

(1)下载地址

Python3下载地址

(2)版本

我这边就选择最新的Python 3.12.4。

2、解压

[root@czg0 GcdwPkg]# tar -xvf Python-3.12.4.tgz

3、切换目录

[root@czg0 GcdwPkg]# cd Python-3.12.4/
[root@czg0 Python-3.12.4]# ll
总用量 1464
-rw-r--r--  1 root root  22013 6月   7 02:26 aclocal.m4
-rwxr-xr-x  1 root root  49348 6月   7 02:26 config.guess
-rwxr-xr-x  1 root root  35276 6月   7 02:26 config.sub
-rwxr-xr-x  1 root root 872093 6月   7 02:26 configure
-rw-r--r--  1 root root 236034 6月   7 02:26 configure.ac
drwxr-xr-x 17 root root   4096 6月   7 02:26 Doc
drwxr-xr-x  2 root root     39 6月   7 02:26 Grammar
drwxr-xr-x  4 root root   4096 6月   7 02:26 Include
-rwxr-xr-x  1 root root  15358 6月   7 02:26 install-sh
drwxr-xr-x 37 root root   8192 6月   7 02:26 Lib
-rw-r--r--  1 root root  13936 6月   7 02:26 LICENSE
drwxr-xr-x  8 root root    164 6月   7 02:26 Mac
-rw-r--r--  1 root root 108038 6月   7 02:26 Makefile.pre.in
drwxr-xr-x  3 root root   4096 6月   7 02:26 Misc
drwxr-xr-x 16 root root   4096 6月   7 02:26 Modules
drwxr-xr-x  4 root root   4096 6月   7 02:26 Objects
drwxr-xr-x  2 root root    285 6月   7 02:26 Parser
drwxr-xr-x  5 root root   4096 6月   7 02:26 PC
drwxr-xr-x  2 root root   8192 6月   7 02:26 PCbuild
drwxr-xr-x  2 root root    216 6月   7 02:26 Programs
-rw-r--r--  1 root root  53474 6月   7 02:26 pyconfig.h.in
drwxr-xr-x  5 root root   4096 6月   7 02:26 Python
-rw-r--r--  1 root root   8703 6月   7 02:26 README.rst
drwxr-xr-x 25 root root   4096 6月   7 02:26 Tools

4、配置

[root@czg0 Python-3.12.4]# ./configure --prefix=/usr/local

这里--prefix指定了安装路径,通常为/usr/local

5、编译

(1)报错:Could not build the ssl module!

[root@czg0 Python-3.12.4]# make
The necessary bits to build these optional modules were not found:
_bz2                  _ctypes               _ctypes_test       
_hashlib              _ssl                  _tkinter           
To find the necessary bits, look in configure.ac and config.log.

Could not build the ssl module!
Python requires a OpenSSL 1.1.1 or newer

Checked 111 modules (31 built-in, 72 shared, 1 n/a on linux-x86_64, 1 disabled, 6 missing, 0 failed on import)

截取了部分,内容太多,make提示警告,应该是系统上的OpenSSL版本太旧,不符合Python的要求。

(2)安装OpenSSL 1.1.1

参考之前的博客:《Linux-学习-05-openssl安装与卸载

(3)安装开发工具和库

[root@czg0 Python-3.12.4]# yum groupinstall "Development Tools"

[root@czg0 Python-3.12.4]# yum install -y bzip2-devel libffi-devel readline-devel sqlite-devel tk-devel xz-devel

6、编译安装

[root@czg0 Python-3.12.4]# make install

7、创建软连接

[root@czg0 Python-3.12.4]# ln -sf /usr/local/bin/python3.12 /usr/bin/python3

[root@czg0 Python-3.12.4]# ln -sf /usr/local/bin/pip3.12 /usr/bin/pip3

8、验证

[root@czg0 Python-3.12.4]# python3 -V
Python 3.12.4

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值