有一些场景需要把python进行降级,以下为操作步骤,请先看下全过程再操作,谢谢。
查看操作系统以及内核版本:
目前操作系统为redhat-9.3版本,自带python版本为3.9.18
-
- 安装Python解释器
# rpm -aq | grep zlib 可以先依次检查以下依赖包是否安装
yum -y install zlib zlib-devel libffi-devel openssl openssl-devel
-
- 下载python解释器源码安装包
cd /opt/
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
tar -xvf Python-3.7.2.tgz
Python官网链接:https://www.python.org/ftp/python/
看自身需求下载哪个版本就下载哪个版本
-
- 进入解压后的目录,执行安装配置安装到/usr/python3文件
cd Python-3.7.2
./configure --prefix=/usr/local/python3 # 安装至/usr/local/python3
安装的时候如有以下报错则进行gcc-c++安装,具体报错具体分析哈
[root@gauss01 Python-3.7.2]# ./configure --prefix=/usr/local/python3
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.7... no
checking for python3... python3
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/opt/Python-3.7.2':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
具体解决方式
yum install gcc-c++ -y
-
- 编译安装
make && sudo make install
- 5.建立软连接
创建软连接前要是existed,就需要删除之前的链接
比如:cd /usr/bin/
mv python3 python3.bak
python或者python3自行看好
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
-
- 检查版本
python -V