1、切换工作目录至/usr/local
在Linux系统下,路径/usr/local相当于C:/Progrem Files/,通常安装软件时便安装到此目录下。
cd /usr/local
yum -y install wget
2、下载目标python版本压缩包
wget http://npm.taobao.org/mirrors/python/3.8.0/Python-3.8.0.tgz
3、解压压缩包
tar -xzf Python-3.8.0.tgz
4、进入文件夹
cd Python-3.8.0
5、编译与安装
这里注意一下哈:
1、3.6的依赖 有需要再逐步加上这些依赖吧
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
2、3.7的依赖包(一定要在安装前先install 否则安装会报错)
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel libffi-devel
./configure --prefix=/usr/local/Python-3.8.0
报错:缺少GCC套件,安装gcc套件后解决
yum install gcc
输入y
然后
./configure --prefix=/usr/local/Python-3.8.0
make clean
make && make altinstall
检查版本信息
[root@aubin02 Python-3.8.0]# python
Python 2.7.5 (default, Aug 4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
cd /usr/bin/
备份之前的python
mv python python.bak
创建软连接 -f可以覆盖之前的软连接
[root@aubin02 bin]# ls -ll |grep python
lrwxrwxrwx. 1 root root 9 Mar 15 16:22 python2 -> python2.7
-rwxr-xr-x. 1 root root 7136 Aug 4 2017 python2.7
lrwxrwxrwx. 1 root root 7 Mar 15 16:22 python.bak -> python2
[root@aubin02 bin]# ln -s /usr/local/Python-3.8.0/python /usr/bin/python
[root@aubin02 bin]# python -V
Python 3.8.0
[root@aubin02 bin]#
图示:
——————————————————————————
升级完Python3记得修改yum相关配置,否则如下报错
报错:
[root@wyyyy01 ~]# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
# Executing docker install script, commit: 93d2499759296ac1f9c510605fef85052a2c32be
+ sh -c 'yum install -y -q yum-utils'
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
+ sh -c 'yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo'
File "/usr/bin/yum-config-manager", line 135
except yum.Errors.RepoError, e:
^
SyntaxError: invalid syntax
解决:
vim /usr/bin/yum-config-manager
修改:#!/usr/bin/python -tt 改为 #!/usr/bin/python2 -tt
————————————————————————————
others:
vi /usr/bin/yum
修改:#!/usr/bin/python 改为 #!/usr/bin/python2
#!/usr/bin/python 改为 #!/usr/bin/python2
——————————————————————————
执行yum install tree报错,解决办法
vi /usr/libexec/urlgrabber-ext-down
问题分析:原因同上,将Python指向就版本即可。
解决方案:
#vi /usr/libexec/urlgrabber-ext-down
更改配置文件第一行#!/usr/bin/python为#!/usr/bin/python_old即可
——————————————————————————————
最后验证,Python3.8安装完成!