centos7使用源码从python2升级到python3,干货值得收藏

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

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

步骤一 安装编译环境包

yum install gcc-c++ gcc make cmake zlib-devel bzip2-devel openssl-devel ncurse-devel libffi-devel -y

步骤二 在线下载python 3.7源码包

[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

步骤三 解压并配置

#解压文件
[root@localhost mnt]# tar xvf Python-3.7.2.tar.xz
#进入python3.7.2目录
[root@localhost mnt]# cd Python-3.7.2
#创建目录
[root@localhost Python-3.7.2]# mkdir -p /usr/local/python3
#配置安装目录
[root@localhost Python-3.7.2]# ./configure --prefix=/usr/local/python3 --enable-optimizations

步骤四 编译及安装

[root@localhost Python-3.7.2]# make && make install

步骤五 更换系统默认python版本

1、备份原系统旧版本python

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

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

[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

3、查看python版本

[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)
发布了32 篇原创文章 · 获赞 1 · 访问量 926

猜你喜欢

转载自blog.csdn.net/sinat_28521487/article/details/105332252