配置深度学习conda环境时,换源是一件很重要的事,最简洁的换源命令如下(打开终端,任意环境输入):
!!!首先确保已经正确安装了Anaconda,不会安装的可以在我主页中找教程!!!
conda换源:
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
pip换源:
pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/
pip config set install.trusted-host https://pypi.mirrors.ustc.edu.cn/
以上镜像源选择的是中科大的镜像库,个人感觉速度还是比较快的,当然也可以选择其他镜像网站(推荐清华Tuna镜像站和南京大学镜像站,其他镜像站多数也是重定向到这两个镜像站)
清华源:
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/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
南大源:
conda config --add channels https://mirrors.nju.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.nju.edu.cn/anaconda/pkgs/free/
专业工具包仓库:https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/
例如:
pytorch仓库安装源:https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
生物学仓库安装源:https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
如果想了解更多关于换源原理的可以接着往下看...(ubuntu系统)
执行完以上四条命令后,可以在以下路径发现多的两个配置文件:(需要显示隐藏文件)
conda配置文件路径:~/.condarc
pip配置文件路径:~/.config/pip/pip.conf
打开这两个文件就可以看到我们新设置的镜像源了,也可以在这里直接设置,上下顺序就是优先级顺序,从上至下进行检索,一般最后一行是default也就是默认源,另外需要注意的是pip使用镜像源时,还需要额外配置一个trust-host,也就是信任该域名中的软件包。
conda一般要设置两个源,一个是main主仓库,都是官方维护的镜像站,还有一个是conda-forge这个仓库是一个很大的第三方软件包仓库,算是半官方仓库,有相当一部分包要从这个仓库中下载。
另外pip还有临时换源命令如下:
pip install numpy -i http://pypi.douban.com/simple/ -trust-host http://pypi.douban.com/
例子中是使用豆瓣源安装numpy,还可使用以下pip源:
阿里云 http://mirrors.aliyun.com/pypi/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/