1、個人安裝環境
1.1 Windows7x64 + Python 3.7.3
1.2 Centos7 + 3.6.8
2、默認安裝源
默認情況下使用的是pythonhosted.cn這個域名,這個就是python官方的域名,對應的網站是在國外。通常下載速度較慢,容易出錯。

3、更改國內安裝源
3.1 國內安裝員列舉
- 阿里:https://mirrors.aliyun.com/pypi/simple
- 豆瓣:http://pypi.douban.com/simple/
- 清華大學:https://pypi.tuna.tsinghua.edu.cn/simple
- 中國科學技術大學: https://pypi.mirrors.ustc.edu.cn/simple
- 華中理工大學: http://pypi.hustunique.com/simple
- 山東理工大學: http://pypi.sdutlinux.org/simple
3.2 速度測試
使用Windows cmd進行ping測試,如
C:\Users\admin>ping aliyun.com
正在 Ping aliyun.com [2401:b180:1:50::f] 具有 32 字節的數據:
來自 2401:b180:1:50::f 的回復: 時間=17ms
來自 2401:b180:1:50::f 的回復: 時間=17ms
來自 2401:b180:1:50::f 的回復: 時間=18ms
來自 2401:b180:1:50::f 的回復: 時間=16ms
2401:b180:1:50::f 的 Ping 統計信息:
數據包: 已發送 = 4,已接收 = 4,丟失 = 0 (0% 丟失),
往返行程的估計時間(以毫秒為單位):
最短 = 16ms,最長 = 18ms,平均 = 17ms
C:\Users\admin>ping douban.com
正在 Ping douban.com [154.8.131.172] 具有 32 字節的數據:
來自 154.8.131.172 的回復: 字節=32 時間=29ms TTL=50
來自 154.8.131.172 的回復: 字節=32 時間=28ms TTL=50
來自 154.8.131.172 的回復: 字節=32 時間=27ms TTL=50
來自 154.8.131.172 的回復: 字節=32 時間=28ms TTL=50
154.8.131.172 的 Ping 統計信息:
數據包: 已發送 = 4,已接收 = 4,丟失 = 0 (0% 丟失),
往返行程的估計時間(以毫秒為單位):
最短 = 27ms,最長 = 29ms,平均 = 28ms
C:\Users\admin>ping tuna.tsinghua.edu.cn
正在 Ping tuna.tsinghua.edu.cn [2402:f000:1:416:101:6:6:172] 具有 32 字節的數據:
來自 2402:f000:1:416:101:6:6:172 的回復: 時間=73ms
來自 2402:f000:1:416:101:6:6:172 的回復: 時間=71ms
來自 2402:f000:1:416:101:6:6:172 的回復: 時間=71ms
來自 2402:f000:1:416:101:6:6:172 的回復: 時間=70ms
2402:f000:1:416:101:6:6:172 的 Ping 統計信息:
數據包: 已發送 = 4,已接收 = 4,丟失 = 0 (0% 丟失),
往返行程的估計時間(以毫秒為單位):
最短 = 70ms,最長 = 73ms,平均 = 71ms
很明顯,我們這邊使用阿里雲速度較快!
3.3 windows創建或修改pip.ini文件
3.3.1 文件位置確認
pip.ini位置為%USERPROFILE%\pip\pip.ini(注意:以UTF-8無BOM編碼格式保存),USERPROFILE位置使用set命令查看
set
運行結果:
USERPROFILE=C:\Users\admin VBOX_INSTALL_PATH=C:\Program Files\Oracle\VirtualBox\ VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\ windir=C:\Windows windows_tracing_flags=3 windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log
所以pip.int真實位置為C:\Users\admin\pip\pip.ini
3.3.2 修改文件
[global] timeout=300 index-url=https://mirrors.aliyun.com/pypi/simple [install] trusted-host=aliyun.com
3.4 Centos創建或修改pip.ini文件
3.4.1 create file
cd ~ mkdir .pip cd .pip sudo gedit pip.conf
3.4.2 copy and paste below texts
[global] trusted-host=mirrors.douban.com index-url=https://pypi.douban.com/simple/
4、安裝測試
以cmd中安裝django進行測試:
pip install django
運行結果:
Looking in indexes: https://mirrors.aliyun.com/pypi/simple
Collecting django
Downloading https://mirrors.aliyun.com/pypi/packages/c6/b7/63d23df1e311ca0d90f41352a9efe7389ba353df95deea5676652e615420/Django-3.0.3-py3-none-any.whl (7.5MB)
100% |████████████████████████████████| 7.5MB 1.4MB/s
Requirement already satisfied: pytz in c:\programdata\anaconda3\lib\site-packages (from django) (2018.9)
Requirement already satisfied: asgiref~=3.2 in c:\programdata\anaconda3\lib\site-packages (from django) (3.2.3)
Requirement already satisfied: sqlparse>=0.2.2 in c:\programdata\anaconda3\lib\site-packages (from django) (0.3.0)
Installing collected packages: django
Successfully installed django-3.0.3
