【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/
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步