Linux教程

Linux Centos7保留python2.7基础上安装Python3.8.6

本文主要是介绍Linux Centos7保留python2.7基础上安装Python3.8.6,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.安装依赖包

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

2.下载python3.8.6

进入python目录,并下载python3.8.6

cd python3.8.6

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

3.保留python2.7基础上安装python3

3.1、创建python3安装目录

$mkdir -p /usr/local/python3

3.2、解压缩

$tar -zxvf Python-3.8.6.tgz

4.编译安装需要编译器

yum install gcc

3.7后的版本还有安装一个依赖包:

yum install libffi-devel -y

5、进入解压缩目录编译安装

$cd Python-3.8.6

$./configure --prefix=/usr/local/python3

6、编译

make

7、编译成功后,安装

make install

8、建立python3和pip3的软链接

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

检查软链接

[root@localhost bin]# cd /usr/bin

[root@localhost bin]# ll python*

lrwxrwxrwx. 1 root root    7 May  8  2020 python -> python2

lrwxrwxrwx. 1 root root    9 May  8  2020 python2 -> python2.7

-rwxr-xr-x. 1 root root 7136 Nov 20  2015 python2.7

lrwxrwxrwx  1 root root   30 Apr  7 14:09 python3 -> /usr/local/python3/bin/python3

9、将/usr/local/python3/bin加入PATH

vim /etc/profile

加上这个

export PATH=$PATH:$HOME/bin:/usr/local/python3/bin

10、加载环境变量

$source /etc/profile

11、查看python3版本

[root@localhost bin]# python2 -V

Python 2.7.5

[root@localhost bin]# python3 -V

Python 3.8.6

[root@localhost bin]# pip3 -V

pip 20.2.1 from /usr/local/python3/lib/python3.8/site-packages/pip (python 3.8)

这篇关于Linux Centos7保留python2.7基础上安装Python3.8.6的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!