最近大量的配置环境,在此特地记录一下 Python3 的源码安装。由于大陆的不可抗因素,访问 PIP 默认源 pypi.python.org 总是超时,或者下载速度十分缓慢,也记录一下替换 PIP 源的方式。

在此,我们选择的是清华的源 https://pypi.tuna.tsinghua.edu.cn

0x01 编译安装

直接上 Shell 了。

1
2
3
4
5
6
7
8
9
10
11
12
13
yum groupinstall -y 'Development Tools'
yum install -y wget
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel

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

cd Python-3.5.4
./configure --prefix=/usr/local/python3
make && make install -j4

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

0x02 更换 PIP 源

在 Linux 环境下修改默认的镜像源,只需新建 /root/.pip/pip.conf 文件,并添加以下内容即可。

清华源

1
2
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

豆瓣源

1
2
[global]
index-url = https://pypi.douban.com/simple

阿里源

1
2
3
[global]
trusted-host = mirrors.aliyun.com
index-url = http://mirrors.aliyun.com/pypi/simple

0x03 Reference

pip 更换软件镜像源 - 简书