pip conda 国内镜像源 添加与删除

在国内,由于默认pip和conda源速度较慢,可以通过添加国内镜像源如阿里云、中国科技大学、豆瓣和清华大学等提高下载速度。例如,使用pip安装sklearn时,可添加-douban镜像源。对于conda,可配置添加-tuna.tsinghua.edu.cn的channels,并设置show_channel_urls为yes。当不再需要国内镜像源时,可通过查看并移除相应channels来恢复默认源。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当我们在国内时,pip或conda默认源的速度可能很慢,导致下载失败,于是整理了一些国内镜像源。

pip国内源

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


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

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

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

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

使用方法为加 -i 加 url,如下(以安装sklearn为例):

pip install -U scikit-learn -i http://pypi.douban.com/simple 

有时会报错,说

The repository located at pypi.douban.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.douban.com'.

此时请按照提示输入如下命令:

pip install -U scikit-learn -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

如果是使用conda来安装, 执行这两条命令,可以将国内镜像源加入config文件

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

conda config --set show_channel_urls yes

然后再执行即可

conda install scikit-learn

但有时候你添加了国内镜像源之后又出国了,默认的源的速度比清华的快,你想把国内镜像源删除,你可以这样做。先查看channels里是否有清华镜像

conda config --get channels 

如果有,把它移除

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

 

 

参考:https://www.cnblogs.com/sunnydou/p/5801760.html

https://blog.youkuaiyun.com/tangwenbo124/article/details/74784268

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值