【Python】pip安装加速:使用国内镜像源

【Python】pip安装加速:使用国内镜像源

零、使用命令行设置

设置全局镜像源

随便使用下面任一命令即可!

阿里云:

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

豆瓣:

pip config set global.index-url https://pypi.douban.com/simple/

清华大学:

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/

中国科学技术大学:

pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/

遇到的问题,信任镜像源

最新版的pip要求必须使用https,如果源不是https协议的,会报如下错误:

WARNING: The repository located at … is not a trusted or secure host and is being ignored.

WARNING: The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommen
d you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host mirrors.aliyun.com'.
ERROR: Could not find a version that satisfies the requirement requests (from versions: none)
ERROR: No matching distribution found for requests                                           
WARNING: The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommen
d you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host mirrors.aliyun.com'.
WARNING: There was an error checking the latest version of pip.
解决方案一:切换为https的源(推荐)

一般在链接中把http替换成https即可,或者找对应的https源。

解决方案二:临时信任

可以在命令行后加上--trusted-host参数,例如:

pip install -i http://mirrors.aliyun.com/pypi/simple/ 依赖参数 --trusted-host mirrors.aliyun.com

壹、使用文件设置

Windows上按Windows+R键打开运行,输入%userprofile%打开个人文件夹,在个人文件夹中新建.pip目录,在目录中新建文本文档并改名为pip.conf,写入如下内容:

阿里云(http)

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

阿里云(https)

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

其他的源也是类似的,把链接改一下即可:

  • 豆瓣:https://pypi.douban.com/simple/
  • 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/
  • 中国科学技术大学:https://pypi.mirrors.ustc.edu.cn/simple/

叁、参考文档

  1. 国内pip源提示“not a trusted or secure host”解决方案
  2. pip源提示“not a trusted or secure host” 解决
  3. 【Python】已完美解决:WARNING: The repository located at mirrors .aliyun.com is not a trusted or secure host
  4. pip使用国内镜像源(附加全局修改)

猜你喜欢

转载自blog.csdn.net/XiaoYuHaoAiMin/article/details/133636695