anaconda pip 添加国内加速源 镜像源 提升安装速度

我们在使用anaconda或者pip安装python包的时候经常会遇到类似的错误,如Timeout,或者PackagesNotFoundError: The following packages are not available from current channels。一般这些情况都是由于不可描述原因导致的请求连接异常而不能正常安装我们所需要的包。

我们可以指定anaconda的chanles或者在pip安装某个包时临时指定源;通过添加国内的源来加速安装,以及拓宽对所需包的检索范围。

狗头保佑

1、添加清华镜像(源)

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

2、添加豆瓣镜像(源)

conda config --add channels https://pypi.douban.com/anaconda/cloud/conda-forge/
conda config --add channels https://pypi.douban.com/anaconda/cloud/msys2/
conda config --add channels https://pypi.douban.com/anaconda/cloud/bioconda/
conda config --add channels https://pypi.douban.com/anaconda/cloud/menpo/
conda config --add channels https://pypi.douban.com/anaconda/cloud/pytorch/

conda config --set show_channel_urls yes

3、删除源

conda config --remove-key channels

4、pip带源安装

可以临时指定安装所需要的源

pip install -i https://pypi.douban.com/simple tensorflow-gpu==1.14

docker-加速器和源的配置[centos]

1、宿主机的系统时centos,使用yum安装的docker

2、自定义docker 镜像数据的存储路径

  • 操作是:编辑 vim /usr/lib/systemd/system/docker.service,修改ExecStart 带上。–graph和路径即可;
docker.service

3、定义镜像加速器

  • 在早期的版本里是支持直接在docker.servcie文件中修改配置;
  • 设定镜像加速器在 /etc/docker 路径下的daemon.json 中添加如下内容,如果daemon.json不存在,则直接touch一个新文件即可
{ “registry-mirrors” : [“https://registry.docker-cn.com”,”https://docker.mirrors.ustc.edu.cn/”,”https://reg-mirror.qiniu.com/”], “live-restore”: true }

4、在很多下载的images中的Dokerfile文件都是使用 apt-get 去下载对应的包来build 容器的,但是官方的apt-get会很慢,这里我们需要把apt-get的源修改成国内的,我们的加速器主要用的阿里的 。 所以源也尽可能用阿里的 ,因为没有添加网易和163的加速器,直接设计其他的源,会出现域名解析的错误。所以在Dokerfile文件中的apt-get update之前 加入这些命令

RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.listRUN sed -i “s/archive.ubuntu./mirrors.aliyun./g” /etc/apt/sources.listRUN sed -i “s/deb.debian.org/mirrors.aliyun.com/g” /etc/apt/sources.listRUN sed -i ‘s/http:\/\/archive\.ubuntu\.com\/ubuntu\//http:\/\/mirrors\.163\.com\/ubuntu\//g’ /etc/apt/sources.listRUN apt-get clean