pip和conda 添加国内清华镜像 让他下的更快

---2019.12.2号更新,发现阿里云源好用---

永久使用:
Linux下:
修改 ~/.pip/pip.conf (没有.pip目录就在home目录创建一个.pip目录,在创建一个pip.conf文件), 往文件里写入下面两行,内容如下:

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

感觉阿里云的源比清华源好用,而且注意第二行一定要加,下面的清华源添加也是一样的,上面亲测很好用,直接照做

---------------------更新结束--------------

python模块安装,使用国内源可以提高下载速度。

pip源更改:

pip源有好几个,我一直用的清华的pip源,它5分钟同步一次。
临时使用:
pip 后加参数 -i https://pypi.tuna.tsinghua.edu.cn/simple
例1:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas

例2:我想安装tensorflow-gpu1.4.1,执行:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow-gpu==1.4.1

我们可以点进去那个清华链接,这个链接和下面那个conda的清华链接不太一样,注意,有非常多的镜像

 

永久使用:
Linux下:
修改 ~/.pip/pip.conf (没有.pip目录就在home目录创建一个.pip目录,在创建一个pip.conf文件), 往文件里写入下面两行,内容如下:

    [global]
    trusted-host=pypi.tuna.tsinghua.edu.cn
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple

不过有的博客我看到这样写,多了一行:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn

两种应该都可以,global可能是全局,也就是第一种直接在全局下,

  • 2

windows下:
直接在user目录中创建一个pip目录,如:C:\Users\xxxx\pip,新建文件pip.ini,内容如下,注意加trusted-host

要不然老是出错

 [global]
 index-url = https://pypi.tuna.tsinghua.edu.cn/simple
  • 1
  • 2

conda源更改:

conda源国内有清华,中科大,阿里云,注意,同一个源可以加不同的链接,

比如清华的源我之前只加了https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

但是有些包在别的地方,比如pytorch包在

https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch

注意如果需要pytorch, 还需要添加pytorch的镜像

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch

注意:
;'PyTorch 官网给的安装命令需要去掉最后的 -c pytorch ,这样才能享受清华源的高速。

所以可以都加进去

-----------

修改源只需输入如下两行命令:

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

输完后,会在home目录生成一个.condarc文件,后面可以通过编辑这个文件来改变源,比如现在.condarc文件内容如下:

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults
show_channel_urls: true

意思如果用conda安装包,会优先用https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/这个清华源

如果没有,会依次往下顺延至defaults也就是用默认源,有的说把defaults会快点

现在我在想添加一个中科大的源和清华其他的源,直接将链接写入文件,如下:

阿里云好像只有pip的源,conda的没找到,也可以自己点链接进去,看看网址里面都有什么包

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
  - defaults
show_channel_urls: true
  •  
  • 2

就可以了。
中科大的常用源:

conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/

或者直接在.condarc文件写
 

总结:

pip 用阿里或清华源

conda 用清华或中科大

 

 

 

  • 17
    点赞
  • 55
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值