【已解决】Python包下载速度太慢
- Python 拥有非常丰富的库,且我们常用
pip
或conda
来安装各种库。但是,如果遇到网络较差的时候,下载包可能会很慢,耗费较长时间,甚至出现超时无法下载的情况- 可以采用换源的方法来解决这一问题,即换成国内的镜像。
方法一
每次安装库的时候,在命令里加个参数 -i
,并在其后添加一个国内镜像的地址,即可大大提升下载速度。安装命令如下:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple your-lib==version
常见的源有:
- 清华源:https://pypi.tuna.tsinghua.edu.cn/simple/
- 中科大源:https://pypi.mirrors.ustc.edu.cn/simple/
- 华中理工大源:https://pypi.hustunique.com/
- 阿里云:https://mirrors.aliyun.com/pypi/simple/
- 豆瓣:http://pypi.douban.com/simple/
方法二
如果你那儿的网络总是不给力,又不想每次手动添加,可以直接加在配置文件里,一劳永逸。
- 查看 Anaconda 中已有镜像源
conda config --show channels
- 在配置中添加镜像源(以清华源为例)
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
此外,如果你想删除已存在的镜像源,可使用如下命令:
conda config --remove-key channels