liuwenliang的个人博客分享 http://blog.sciencenet.cn/u/liuwenliang

博文

[转载]pip换源问题

已有 2498 次阅读 2023-3-28 23:51 |个人分类:python|系统分类:科研笔记|文章来源:转载

换源方式

这里我们提供两种换源的方式:


临时换源

永久换源

临时换源

临时换源只需要在pip安装包时,加上一个-i参数后接源的url即可:


1.临时换源:

复制代码

#清华源

pip3 install markdown -i https://pypi.tuna.tsinghua.edu.cn/simple

阿里源

pip3 install markdown -i https://mirrors.aliyun.com/pypi/simple/

腾讯源

pip3 install markdown -i http://mirrors.cloud.tencent.com/pypi/simple

豆瓣源

pip3 install markdown -i http://pypi.douban.com/simple/

2.永久换源:

清华源

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

阿里源

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

腾讯源

pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple

豆瓣源

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

换回默认源

pip config unset global.index-url


pip换源的方式

在使用Python安装包工具pip时经常会出现下载很慢的情况,这其中有很大一部分原因和pip的源有关,在我们安装python后,通常python解释器自带pip这个工具,但是这里pip是设置的默认源,也就是官方源:


https://pypi.org/simple,这个源在国内的下载速度是很慢的(精通FQ的大神另说),所以我们为了提高包的下载速度我们可以通过换源来实现。


PYPI国内源路径

阿里云 http://mirrors.aliyun.com/pypi/simple/


豆瓣(douban) http://pypi.douban.com/simple/


清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/


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


下载python中的Django包,这里使用的是豆瓣源

pip install django -i http://pypi.douban.com/simple

显然不是一个一劳永逸的方法,只有下少量包的时候有使用的场景,下面我要介绍永久换源的方法,通过这个方式换源,那么以后我们下载的包就可以全部从这个url中下载了,这样大大减轻了我们的工作量,明显比临时换源的方法更好。


永久换源(更换默认源)

Linux

在根目录下创建/修改~/.pip/pip.confpip配置文件;


进入文件新增/修改内容;


[global]

index-url=http://pypi.douban.com/simple

[install]

trusted-host=pypi.douban.com

保存文件并退出;


Windows

windows在%HOMEPATH%\pip\pip.ini中修改上面第二步的内容;(例如:C:\Users\hp\AppData\Roaming\pip\pip.ini)

保存文件退出;

常见问题

安装包的时候出现


Collecting beautifulsoup4

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 it is recommended to use HTTPS instead, otherwise you may silence this warning and allow it anyways with ‘–trusted-host mirrors.aliyun.com’.

Could not find a version that satisfies the requirement beautifulsoup4 (from versions: )

No matching distribution found for beautifulsoup4

这是一个问题是在pip镜像升级报警,只需要添加信任源即可:


临时换源处理


pip install beautifulsoup4 --trusted-host mirrors.aliyun.com

更换默认源配置(一劳永逸)


[install]

trusted-host=pypi.douban.com

————————————————

版权声明:本文为CSDN博主「笑 瘾」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/weixin_47661174/article/details/124625894




https://blog.sciencenet.cn/blog-3409972-1382180.html

上一篇:ArcMap.exe启动崩溃,提示 ntdll.dll错误,解决方案
下一篇:[转载]从零开始,手把手教你本地部署Stable Diffusion Webui AI绘画(Win系最新版)
收藏 IP: 210.72.26.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-7-17 21:24

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部