linux 安装python3(亲测可用)

首先安装python3所需的基础库

yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel
yum -y install readline-devel zlib-devel gcc wget

接着,下载python3版本并解压,此处以3.8.5为例

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

tar -zxvf Python-3.8.5.tgz

然后,编译、安装

cd Python-3.8.5

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

make -j4   #多核编译,减少等待时间

make install

最后创建软连接

#创建软链接

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

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

可在命令行运行python3命令,检验安装结果。

[root@sdx7 ~]# python3
Python 3.8.5 (default, Mar 20 2023, 13:49:12) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

大功告成!

你可能感兴趣的:(linux,python,运维)