加速的方法无非就是更改包的来源,也就是源位置。
所以我们先理解一下源位置
1. 源位置
所谓的源位置就是你的索引下载包的位置是哪里。打个比方,我们安装tensorflow
的CUDA
时候:版本CUDA10.1
开始,在ubuntu
安装方式是如下命令,
我们以cuda_10.2.89_440.33.01_linux_ppc64le.run
为例子
$ wget http://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux_ppc64le.run
$ sudo sh cuda_10.2.89_440.33.01_linux_ppc64le.run
这里面有一个命令wget
和网址http://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers
这个网址就是我们说的源位置。
为什么下载慢
因为我们的源位置默认是国外的网址地址,一般是从美国提供的云服务下载,索引不到的时候就是从日本下载,所以很慢。
2. conda提速
- 对于
Anaconda
的下载方式就是conda install
了,这个方式可以使用conda install -i 源
的格式下载,但是太慢了,我们就永久更改位置即可,代码如下
# 1. 设置
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
# 2. 生效
conda config --set show_channel_urls yes
这里提供多个源,大家自己选择的来(个人推荐使用尾缀是free
的,这个很稳定比如main
的快)
# 1. 中科大
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
# 2.清华
conda config --add https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
3. pip提速
这个很简单,因为pip
的下载更新命令是pip install/update/upgrade [可选命令] 源位置 包文件名[==版本,默认最新]
,那么在[可选命令]
加上-i
即可,举例如下安装tensorflow
# 从清华安装tensorflow版本号为1.14
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade tensorflow-gpu==1.14.0
其中[可选命令]
常用有下面的。
-i: 指定库的安装源
-U:升级 原来已经安装的包,不带U不会装新版本,带上U才会更新到最新版本。