乐趣区

关于程序员:pip安装更换镜像

原文链接

应用 pip 来装置 python 包有时候装置起来会十分慢,因而须要换成国内的源来减速下载:

1 单次批改源

以 Torch 为例,惯例下载方式为:

pip install torch

批改为阿里源:

pip install -i https://mirrors.aliyun.com/pypi/simple torch

2 批改默认源

如果不想在每一次下载都指定源,能够间接批改默认源。

2.1 Linux

linux 下运行命令:

vi ~/.pip/pip.conf

而后写入如下内容并保留(以阿里源为例):

 [global]
 trusted-host =  mirrors.aliyun.com
 index-url = https://mirrors.aliyun.com/pypi/simple

2.2 Windows

windows 下找到 pip.ini 文件,默认门路为:C:\Users\xxx\AppData\Roaming\pip\pip.ini

而后写入如下内容并保留(以阿里源为例):

 [global]
 trusted-host =  mirrors.aliyun.com
 index-url = https://mirrors.aliyun.com/pypi/simple

3 罕用的国内源

阿里云:http://mirrors.aliyun.com/pyp…

豆瓣:http://pypi.doubanio.com/simple/

清华大学:https://pypi.tuna.tsinghua.ed…

中国科学技术大学:http://pypi.mirrors.ustc.edu….

华中理工大学:http://pypi.hustunique.com/

山东理工大学:http://pypi.sdutlinux.org/

4 常见报错

4.1 若无奈连贯

WARNING: The repository located at pypi.doubanio.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with ‘–trusted-host pypi.doubanio.com’.
ERROR: Could not find a version that satisfies the requirement opencv-python (from versions: none)
ERROR: No matching distribution found for opencv-python

能够将源中的 http 改为 https

4.2 须要 user

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: ‘/anaconda3/lib/python3.7/site-packages/llvmlite-0.28.0.dist-info’
Consider using the --user option or check the permissions.

须要加上 –user:pip install <module> 改为 pip install –user <module>

pip install --user -i https://pypi.tuna.tsinghua.edu.cn/simple torch

 
 

学习更多编程常识,请关注我的公众号:

代码的路

退出移动版