目录

修仙笔记

Centos安装Python3的方法

由于centos7原本就安装了Python2,而且这个Python2不能被删除,因为有很多系统命令,比如yum都要用到。

[root@VM_0_11_centos Python-3.6.2]# python
Python 2.7.5 (default, Apr  9 2019, 14:30:50) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

可以查看位置,一般是位于/usr/bin/python目录下。
which python

安装Python3

首先安装依赖包

yum -y groupinstall "Development tools"
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

然后根据自己需求下载不同版本的Python3,我下载的是Python3.6.2

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

我的存放目录是/usr/local/python3

mkdir /usr/local/python3 #建立一个空文件夹

然后解压压缩包,进入该目录,安装Python3

tar -xvJf  Python-3.6.2.tar.xz
cd Python-3.6.2
./configure --prefix=/usr/local/python3
make && make install

最后创建软链接

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

在命令行中输入python3测试

[root@VM_0_11_centos Python-3.6.2]# python3

Python 3.6.2 (default, Apr 24 2019, 07:47:35) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.

标题:Centos安装Python3的方法
作者:H3cke
地址:https://cnci.xyz/articles/2019/04/24/1556064235887.html