CentOS7安装Python3

CentOS7安装Python3

系统环境:CentOS 7.6

Python 版本:Python-3.6.8

1. 环境依赖

Python3.x 的安装需要依赖这四个组件:gcc, zlib,zlib-devel,openssl-devel;所以需要预先安装,命令如下:

 [root@localhost ~]# yum -y install gcc zlib  zlib-devel openssl-devel 

2. 下载编译

Python 官方下载地址: Download Python | Python.org

Python 加速地址:Index of python-local

[root@localhost ~]# wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz         (官方下载地址)
[root@localhost ~]# wget https://repo.huaweicloud.com/python/3.6.8/Python-3.6.8.tgz       (华为镜像站) 

3. 解压编译

 [root@localhost ~]# tar -zxvf Python-3.6.8.tgz

进入根目录进行编译,可以指定编译安装的路径,这里我们指定为 /usr/local/python3.6 :

 [root@localhost ~]# cd Python-3.6.8
 [root@localhost Python-3.6.8]# ./configure --prefix=/usr/local/python3.6 
 [root@localhost Python-3.6.8]# make && make install 

4. 环境变量配置

 [root@localhost ~]# vim /etc/profile
  export PYTHON_HOME=/usr/local/python3.6
  export PATH=${PYTHON_HOME}/bin:$PATH

使得配置的环境变量立即生效:

[root@localhost ~]# source /etc/profile

 也可以创建软链接

[root@localhost ~]# ln -s /usr/local/python3.6/bin/python3   /usr/bin/python3
[root@localhost ~]# ln -s /usr/local/python3.6/bin/pip3    /usr/bin/pip3

5. 验证安装是否成功

输入 python3 命令,如果能进入 python 交互环境,则代表安装成功:

[root@localhost ~]# python3
Python 3.6.8 (default, Mar 29 2019, 10:17:41)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1+1
2
>>> exit()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值