20200609
[root@mysql_master 17:00:23]:/usr/libexec
#python
Python 2.7.5 (default, Aug 7 2019, 00:51:29)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
切记不可随意删除系统自带python版本,因为系统有很多软件依赖着
yum
手动下载并编译python源代码安装
cd /usr/local/src
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
tax -xvf Python-3.6.8.tgz
./configure --prefix=/usr/local/python3.6.8 --with-ssl
sudo make
sudo make install
1.查看python现有信息
2.重命名旧的python软链
mv /usr/bin/python /usr/bin/python.bak
mv /usr/bin/pip /usr/bin/pip.bak
3.建立python新软链和pip软链
ln -s /usr/local/python3.6.8/bin/python3 /usr/bin/python368
ln -s /usr/local/python3.6.8/bin/pip3 /usr/bin/pip
4.测试版本
root@chenwx:/usr/bin# python
Python 3.6.8 (default, Jun 9 2020, 14:37:48)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
如上步操作所示,已经制定python3.6.8版本是默认python版本
alternatives --install /usr/bin/python python /usr/bin/python2.7 1
alternatives --install /usr/bin/python python /usr/bin/python3.6 2
alternatives --install /usr/bin/pip pip /usr/bin/pip2.7 1
alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.6 2
设置默认版本
alternatives --config python
vim /usr/libexec/urlgrabber-ext-down
vi /usr/bin/yum
首行的#! /usr/bin/python
都改为#! /usr/bin/python2.7
firewall-cmd也需要手工设置一下
# vim /usr/bin/firewall-cmd
首行改为
#!/usr/bin/python2.7 -Es
原文:https://www.cnblogs.com/cnhope/p/13079523.html