安装Python依赖包:
[root@Python src]# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
下载Python源码包:
[root@Python src]# wget ttp://mirrors.sohu.com/python/3.6.4/Python-3.6.4.tgz
编译、安装:
[root@Python /]# tar -xzvf /usr/local/src/Python-3.6.4.tgz -C /usr/local/src/
[root@Python /]# cd /usr/local/src/Python-3.6.4
[root@Python Python-3.6.4]# ./configure --prefix=/usr/local/python
[root@Python Python-3.6.4]# make -j 4
[root@Python Python-3.6.4]# make install
查看扩展安装包:
[root@Python /]# /usr/local/python/bin/pip3 list
pip (8.1.1) setuptools (20.10.1)
添加Python命令到环境变量:
[root@Python /]# vim ~/.bash_profile
PATH=$PATH:$HOME/bin
改为:
PATH=$PATH:$HOME/bin:/usr/local/python/bin
使环境变量生效:
[root@Python /]# source ~/.bash_profile
查看Python版本:
[root@Python /]# python3 -V
Python 3.6.4
更改系统默认python版本为Python3.6
[root@Python /]# mv /usr/bin/python /usr/bin/python2.6
[root@Python /]# ln -s /usr/local/python/bin/python3.6 /usr/bin/python
核对Python版本:
[root@Python /]# python -V
Python 3.6.4
解决python升级后,YUM不能正常工作的问题:
#vi /usr/bin/yum
将文件头部的 #!/usr/bin/python
改成 #!/usr/bin/python2.6