升级原因:由于2.7后面很多功能不支持,升级到3.7版本会避免掉很多问题
查看当前版本
[root@localhost Python-3.7.4]# python -V
Python 2.7.5
- 安装依赖
yum install -y zlib-devel bzip2-devel openssl-devel libffi-devel ncurese-devel wget gcc gcc-c++ lrzsz
- 下载源码
# 源码地址 https://www.python.org/ftp/python
cd /opt/python
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
- 编译源码
[root@localhost Python-3.7.4]# pwd
/opt/python/Python-3.7.4
[root@localhost Python-3.7.4]# ls
aclocal.m4 config.status Grammar LICENSE Makefile.pre.in PC pyconfig.h.in python-gdb.py
build config.sub Include m4 Misc PCbuild python README.rst
CODE_OF_CONDUCT.rst configure install-sh Mac Modules Programs Python setup.py
config.guess configure.ac Lib Makefile Objects pybuilddir.txt python-config Tools
config.log Doc libpython3.7m.a Makefile.pre Parser pyconfig.h python-config.py
[root@localhost Python-3.7.4]# ./configure --prefix=/usr/local/python3.7
[root@localhost Python-3.7.4]# make && make install
- 替换版本
[root@localhost Python-3.7.4]# mv /usr/bin/python /usr/bin/python2.7.bk
[root@localhost Python-3.7.4]# ln -s /usr/local/python3.7/bin/python3.7 /usr/bin/python
[root@localhost Python-3.7.4]# ln -s /usr/local/python3.7/bin/pip3 /usr/bin/pip
ln: failed to create symbolic link ‘/usr/bin/pip’: File exists
[root@localhost Python-3.7.4]# mv /usr/bin/pi
pic pinentry ping pinky pip2
piconv pinentry-curses ping6 pip pip2.7
[root@localhost Python-3.7.4]# mv /usr/bin/pi
pic pinentry ping pinky pip2
piconv pinentry-curses ping6 pip pip2.7
[root@localhost Python-3.7.4]# mv /usr/bin/pip /usr/bin/pip2.7.bk
[root@localhost Python-3.7.4]# ln -s /usr/local/python3.7/bin/pip3 /usr/bin/pip
[root@localhost Python-3.7.4]# python -V
Python 3.7.4
[root@localhost Python-3.7.4]# pip -V
pip 19.0.3 from /usr/local/python3.7/lib/python3.7/site-packages/pip (python 3.7)
[root@localhost Python-3.7.4]#
- 更新yum
#更改第一行为以下内容
vi /usr/bin/yum
#!/usr/bin/python2.7
vi /usr/libexec/urlgrabber-ext-down
#!/usr/bin/python2.7