系统相关
首页 > 系统相关> > python centos7安装python3

python centos7安装python3

作者:互联网

目录

python centos7安装python3

centos7默认的python版本是2.7,现在想升级python3,同时保留python2.7

官网下载地址: https://www.python.org/ftp/python/

安装前准备

//执行
which python |xargs ls -l
//可以看到指向了Python2
lrwxrwxrwx 1 root root 7 Sep  9 17:44 /usr/bin/python -> python2

安装依赖包

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

添加epel扩展源

yum -y install epel-release

安装pip

yum -y install python-pip

用pip装wget

pip install wget

下载python3

用wget下载python3的源码包,或者自己先下载好,上传到服务器再安装,如果网络快可以直接安装

wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz

编译python3源码包,解压

xz -d Python-3.6.8.tar.xz 
tar -xf Python-3.6.8.tar

编译

进入解压后的目录,依次执行下面命令进行手动编译

cd Python-3.6.8
./configure prefix=/usr/local/python3
make && make install

安装依赖zlib、zlib-deve

yum -y install  zlib zlib-devel

添加软链接,将原来的链接备份

mv /usr/bin/python /usr/bin/python.bak

添加软连接

ln -s /usr/local/python3/bin/python3.6 /usr/bin/python

验证

python -V

标签:python,zlib,devel,centos7,usr,安装,python3
来源: https://www.cnblogs.com/liwenchao1995/p/16673676.html