python2.7.X 升级至Python3.6.X

Posted huandada

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python2.7.X 升级至Python3.6.X相关的知识,希望对你有一定的参考价值。

安装Python3

 

项目是在py3环境下进行编码的,正好yczhang默认的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.6.x

 1 [[email protected] ~]# wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz

可能你需要通过yum -y install wget

 

解压编译安装

[[email protected] ~]# tar xf Python-3.6.0.tgz

[[email protected] ~]# cd Python-3.6.0

[[email protected] Python-3.6.0]# ./configure --prefix=/usr/local/python3.6

[[email protected] Python-3.6.0]# make

[[email protected] Python-3.6.0]# make altinstall

pip3python3创建链接

[[email protected] Python-3.6.0]# ln -fs /usr/local/python3.6/bin/python3 /usr/local/bin/

[[email protected] Python-3.6.0]# ln -fs /usr/local/python3.6/bin/pip3 /usr/local/bin/

[[email protected] Python-3.6.0]# mv /usr/bin/python /usr/bin/python_old

[[email protected] Python-3.6.0]# ln -fs /usr/local/python3.6/bin/python3.6 /usr/bin/python

[[email protected] Python-3.6.0]# ln -fs /usr/local/python3.6/bin/pip3.6 /usr/bin/pip

验证安装

[[email protected] Python-3.6.0]# pip -V

pip 9.0.1 from /usr/local/python3.5/lib/python3.5/site-packages (python 3.6)

[[email protected] Python-3.6.0]# python -V

Python 3.6.0

修改yum文件,否则yum将无法下载

vim /usr/bin/yum

 

 

#!/usr/bin/python

 

修改为

#!/usr/bin/python2.7

 

保存即可生效

以上是关于python2.7.X 升级至Python3.6.X的主要内容,如果未能解决你的问题,请参考以下文章

CentOS 7从Python 2.7升级至Python3.6.1

linux 从Python 2.7升级至Python3.6.1

树莓派升级Python至3.6

Django 和 mod_wsgi python 版本?

python3.6的pip升级不到22.31

python3.6升级及setuptoolspip安装