Centos 7 安装Python3.7.2 环境

更换YUM源:

安装wget

yum -y install wget
[root@code-server ~]# cd /etc/yum.repos.d/
[root@code-server yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repobak

从网关下载aliyun yum源

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo    
yum clean all
yum makecache

1.安装Python依赖环境

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 gcc

2.下载python3

下载Python3    https://www.python.org/downloads/  (直接wget可能会很慢直接从网上下载的版本3.7.2)

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

 

tar -xf Python-3.7.2.tar.xz
cd  Python-3.7.2
./configure --prefix=/usr/local/python3  
#(设置Python的安装路径),此时会有如下的报错

3.make

#安装依赖包
yum install -y libffi-devel
#安装python
make && make install

4.增加环境变量

建立软链接

ln -s /python3.7.2/bin/python3 /usr/bin/python3

将/python3.7.2/bin/ 加入PATH

vi ~/.bash_profile

修改完记得执行行下面的命令,让上一步的修改生效:

source ~/.bash_profile

执行时python要改成python3,或者python脚本头部声明要改为#!/usr/bin/python3

pip3升级

pip3 install --upgrade pip
阅读剩余
THE END