Linux7.5下升级安装python3.7.4

参考链接:https://www.cnblogs.com/tssc/p/7762998.html

众所周知,在2020年python官方将不再支持2.7版本的python,所以使用3.x版本的python是必要的,但是linux中默认安装的python一般是2.6和2.7版本的,要是使用linux下的python就很有必要升级一下
1.检查确认系统的相关信息

[root@hadoop002 etc]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 
[root@hadoop002 etc]# uname -a
Linux hadoop002 3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@hadoop002 etc]# python -V
Python 2.7.5

当前的python版本号为2.7.5
2.下载安装Python-3.7.4

//下载python3.7.4安装包
[root@hadoop002 ~]# cd software/
[root@hadoop002 software]# wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
//解压编译安装
[root@hadoop002 software]# tar -zxf Python-3.7.4.tgz -C ~/app
[root@hadoop002 software]# cd ../app/Python-3.7.4
[root@hadoop002 Python-3.7.4]# yum install make gcc gcc-c++ 
[root@hadoop002 Python-3.7.4]# ./configure
[root@hadoop002 Python-3.7.4]# make & make install

编译安装(make install)时抛错了 ModuleNotFoundError: No module named '_ctypes',解决办法:
3.7版本需要一个新的包libffi-devel,安装此包之后再次进行编译安装即可。

yum install libffi-devel -y

3.安装完成,更改默认的python版本

//检查当前默认的python2
[root@hadoop002 bin]# ll /usr/bin/python*
lrwxrwxrwx 1 root root    7 Nov 29  2018 /usr/bin/python -> python2
lrwxrwxrwx 1 root root    9 Nov 29  2018 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 7216 Jul 13  2018 /usr/bin/python2.7
-rwxr-xr-x 1 root root 1835 Jul 13  2018 /usr/bin/python2.7-config
lrwxrwxrwx 1 root root   16 Nov 29  2018 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root   14 Nov 29  2018 /usr/bin/python-config -> python2-config
//检查新安装的python3
[root@hadoop002 Python-3.7.4]# ll /usr/local/bin/python*
lrwxrwxrwx 1 root root        9 Oct 14 19:08 /usr/local/bin/python3 -> python3.7
-rwxr-xr-x 2 root root 13988168 Oct 14 19:08 /usr/local/bin/python3.7
lrwxrwxrwx 1 root root       17 Oct 14 19:08 /usr/local/bin/python3.7-config -> python3.7m-config
-rwxr-xr-x 2 root root 13988168 Oct 14 19:08 /usr/local/bin/python3.7m
-rwxr-xr-x 1 root root     2902 Oct 14 19:08 /usr/local/bin/python3.7m-config
lrwxrwxrwx 1 root root       16 Oct 14 19:08 /usr/local/bin/python3-config -> python3.7-config
//修改默认的python
[root@hadoop002 Python-3.7.4]# cd /usr/bin
[root@hadoop002 bin]# rm -rf /usr/bin/python
[root@hadoop002 bin]# ln -s /usr/local/bin/python3 /usr/bin/python
//检查修改后的python版本
[root@hadoop002 bin]# python -V
Python 3.7.4
[root@hadoop002 bin]# python2 -V
Python 2.7.5
[root@hadoop002 bin]# python3 -V
Python 3.7.4

可以看到,默认打开的python版本已经是3.6.2,至此python的版本已经升级成功
4.后续的软件问题处理
python的默认版本修改为3.x之后,系统对于yum的调用会出问题,所以需要修改下yum的相关配置

[root@hadoop002 bin]# vi /usr/bin/yum
#!/usr/bin/python2
[root@hadoop002 bin]# vi /usr/libexec/urlgrabber-ext-down
#! /usr/bin/python2

这样,修改后的yum依然可以调用python2.7.5的python,在使用yum安装软件时就不会报错了

你可能感兴趣的:(Linux7.5下升级安装python3.7.4)