【Python零基础学习】python 2.7.x升级刀3.6.X

centos7 服务器下想把python2.7.X升级到3.6

下载

wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz

1
[me@VM_0_8_centos ~]# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz

解压tgz包

tar -zxvf Python-3.6.4.tgz

1
[me@VM_0_8_centos ~]# tar -zxvf Python-3.6.4.tgz

开始安装

先切换到解压后的目录下

1
[me@VM_0_8_centos Python-3.6.4]# cd Python-3.6.4/

配置

1
[me@VM_0_8_centos Python-3.6.4]# ./configure --prefix=/usr/local/python3.6

开始编译

1
[me@VM_0_8_centos Python-3.6.4]# make

在编译过程中发现报错,zipimport.ZipImportError: can’t decompress data; zlib not available

1
2
3
zipimport.ZipImportError: can't decompress data; zlib not available
Makefile:1079: recipe for target 'install' failed
make: *** [install] Error 1

经过分析&查找相关问题,缺乏一些依赖包,因此先继续安装依赖包
sudo yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel

1
[me@VM_0_8_centos Python-3.6.4]# sudo yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel

确认安装成功之后,继续执行

1
[me@VM_0_8_centos Python-3.6.4]# make

编译终于成功,然后安装

1
[me@VM_0_8_centos Python-3.6.4]# make install

修改软链

1
2
[me@VM_0_8_centos Python-3.6.4]# ln -fs /usr/local/python3.6/bin/python3.6 /usr/bin/python
[me@VM_0_8_centos Python-3.6.4]# ln -fs /usr/local/python3.6/bin/pip3.6 /usr/bin/pip

这样我们在输入python的时候,其实引用的是3.6下的python了

验证下

1
2
[me@VM_0_8_centos Python-3.6.4]# python -V
Python 3.6.4
1
2
[me@VM_0_8_centos Python-3.6.4]# pip -V
pip 9.0.1 from /usr/local/python3.6/lib/python3.6/site-packages (python 3.6)

我们可以继续升级下 pip

1
[me@VM_0_8_centos Python-3.6.4]# python -m pip install --upgrade pip

在验证下版本,升级完成!

坚持原创技术分享,谢谢鼓励我继续创作!