详解Centos7升级python 2.7至Python 3.7

centos 7 版本默认情况下是安装的是python2.7,但随着python3的功能不断完善,很多人喜欢用python3进行开发。

详解Centos7升级python 2.7至Python 3.7

今天记录一下在centos7上,使用源码python2升级到python3。

安装编译环境包

<code>yum install gcc-c++ gcc make cmake zlib-devel bzip2-devel openssl-devel ncurse-devel libffi-devel -y/<code>

在线下载python 3.7源码包

<code>[root@localhost ~]# cd  /mnt/
[root@localhost mnt]#
[root@localhost mnt]# wget https://mirrors.huaweicloud.com/python/3.7.2/Python-3.7.2.tar.xz/<code>

解压并配置

解压文件

<code>[root@localhost mnt]# tar xvf Python-3.7.2.tar.xz/<code>

进入python3.7.2目录

<code>[root@localhost mnt]# cd Python-3.7.2/<code>

创建目录

<code>[root@localhost Python-3.7.2]# mkdir -p /usr/local/python3/<code>

配置安装目录

<code>[root@localhost Python-3.7.2]# ./configure --prefix=/usr/local/python3 --enable-optimizations/<code>

编译及安装

<code>[root@localhost Python-3.7.2]# make && make install/<code>

更换系统默认python版本

1、备份原系统旧版本python

<code>[root@localhost Python-3.7.2]# mv /usr/bin/python /usr/bin/python.bak/<code>

2、配置环境环境:创建新版本python和pip的软链接

<code>[root@localhost Python-3.7.2]# ln -s /usr/local/python3/bin/python3.7 /usr/bin/python
[root@localhost Python-3.7.2]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip/<code>

3、查看python版本

<code>[root@localhost Python-3.7.2]# python -V
Python 3.7.2
[root@localhost Python-3.7.2]# pip -V
pip 18.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)/<code>


分享到:


相關文章: