正在进入ing...

python&anacondda更换国内清华、阿里源

发布时间:2020-09-08 浏览量: 12298 文章分类: python

因为我们国内的墙的问题,所以在访问境外网站的时候特别慢,甚至有的网站都打不开,而python的pip又是平时使用非常高的安装第三方插件的功能,所以直接pip install xxxx速度非常慢,而很多大厂都自己做了国内的镜像源方便我们使用。所以正常情况建议在安装晚python后,顺带将pip的源直接换为国内源,如果使用anaconda的话,也直接设置成国内源即可。我自己经常使用的是清华、阿里源,所以这里也都以清华源、阿里源来作为说明。

pip换源

windows更换

先创建pip文件夹,然后在里面创建pip.ini文件,并贴上以下内容

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

Linux&Mac

直接修改~/.pip/pip.conf(没有就创建一个),内容如下

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

anaconda 换源

windows更换

直接在命令行中输入以下命令即可添加清华源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes

Linux&Mac更换

直接在~/.condarc中写以下文件

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