centos7 python2与python3共存
环境
由于centos7默认自带有python2.7.5,所有只需要安装python3就可以了
##1、安装依赖包,用于编译python3
# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-dev libffi-devel
##2、获取python3.8.5软件包
# cd /usr/local/src/
# wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz
##3、解压安装
# tar -xvf Python-3.8.5.tar.xz
# cd Python-3.8.5
# ./configure --prefix=/usr/local/python3 ##也可以指定安装到别的目录 ./configure --prefix=/data/service/python3 根据自己的磁盘挂载目录为准
# make && make install
这是 ./configure编译也可以
##4、建立软连接
ln -sf /usr/local/python3/bin/python3 /usr/bin/python3
ln -sf /usr/local/python3/bin/pip3 /usr/bin/pip3
##、检查是否安装成功
# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
# python3
Python 3.8.5 (default, Sep 11 2019, 14:09:47)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
此时就表示已经安装成功!
好了,这就是centos7 python2与python3共存的方法了,如有问题可与博主一起交流讨论!