打開一個Terminal:
換yum源:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup && curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && yum makecache
安裝python3
yum -y install epel-release zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make openldap-devel && curl -O https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz && tar -xvJf Python-3.6.6.tar.xz && cd Python-3.6.6 && ./configure prefix=/usr/local/python3 && make && make install && ln -s /usr/local/python3/bin/python3 /usr/bin/python3.6 && ln -s /usr/local/python3/bin/python3 /usr/bin/python3 && cd .. && rm -rf Python-3.6.*
如果出現如下錯誤:否則忽略
解決辦法:
cd /etc/pki/rpm-gpg/ wget https://archive.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
使用豆瓣pip源加速:
創建pip.conf
內容如下:
[global] timeout = 60 index-url = http://pypi.douban.com/simple trusted-host = pypi.douban.com
命令行執行:
yum -y install python36-devel python36-setuptools && easy_install-3.6 pip && mkdir /root/.pip && mv pip.conf ~/.pip