首页 > 其他 > 详细

更改PIP默认安装源

时间:2020-02-16 18:01:37      阅读:109      评论:0      收藏:0      [点我收藏+]

1、个人安装环境

1.1 Windows7x64

1.2 Python 3.7.3

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 创建或修改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\VirtualBoxVS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Toolswindir=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

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

 

更改PIP默认安装源

原文:https://www.cnblogs.com/hester/p/12317171.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!