python2.7.X 升级至Python36.X
安装Python3
项目是在py3环境下进行编码的,正好Centos默认的py版本是2,我们还需要安装py3才能让程序run起来,在此之前,需要安装开发工具包,因为要编译安装Python
[[email protected] ~]# yum -y group install "Development Tools"
安装Python的依赖包,不安装依赖可能安装完成后没有pip3 软件。
[[email protected] ~]# yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel vim
下载目前最新的Python3.5.x
[[email protected] ~]# wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tgz
可能你需要通过yum -y install wget
解压编译安装
[[email protected] ~]# tar xf Python-3.5.3.tgz
[[email protected] ~]# cd Python-3.5.3
[[email protected] Python-3.5.3]# ./configure --prefix=/usr/local/python3.5
[[email protected] Python-3.5.3]# make
[[email protected] Python-3.5.3]# make altinstall
为pip3和python3创建链接
[[email protected] Python-3.5.3]# ln -fs /usr/local/python3.5/bin/python3 /usr/local/bin/
[[email protected] Python-3.5.3]# ln -fs /usr/local/python3.5/bin/pip3 /usr/local/bin/
[[email protected] Python-3.5.3]# mv /usr/bin/python/usr/bin/python_old
[[email protected] Python-3.5.3]# ln -fs /usr/local/python3.5/bin/python3.5 /usr/bin/python
[[email protected] Python-3.5.3]# ln -fs /usr/local/python3.5/bin/pip3.5 /usr/bin/pip
验证安装
[[email protected] Python-3.5.3]# pip -V
pip 9.0.1 from /usr/local/python3.5/lib/python3.5/site-packages (python 3.5)
[[email protected] Python-3.5.3]# python -V
Python 3.5.3
修改yum文件,否则yum将无法下载
vim /usr/bin/yum
将#!/usr/bin/python修改为#!/usr/bin/python2.7保存即可生效