325 words
2 minutes
Pip 与 Conda 国内换源指南
pip
1.临时换源:
清华源
pip install xxxx -i https://pypi.tuna.tsinghua.edu.cn/simple阿里源
pip install xxxx -i https://mirrors.aliyun.com/pypi/simple/腾讯源
pip install xxxx -i http://mirrors.cloud.tencent.com/pypi/simple豆瓣源
pip install xxxx -i http://pypi.douban.com/simple/将xxxx换成需要安装的包的名字
2.永久换源:
清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple阿里源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/腾讯源
pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple豆瓣源
pip config set global.index-url http://pypi.douban.com/simple/3.换回默认源
pip config unset global.index-urlconda
1.临时换源:
conda install 包名 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/2.永久换源:
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 --set show_channel_urls yes验证命令:
conda config --show channels看到输出里有tsinghua字样就说明换源成功啦!
常见翻车现场急救指南
问题1:换源后还是下载慢?
试试清理缓存大法:
conda clean -i问题2:某些包找不到怎么办?
临时切回默认源试试:
conda install -c defaults 包名问题3:想换其他镜像源?
- 中科大源:
https://mirrors.ustc.edu.cn/anaconda/pkgs/main/ - 阿里云源:
https://mirrors.aliyun.com/anaconda/pkgs/main/
高级玩家必备技巧
# 查看当前所有镜像源conda config --get channels
# 删除指定镜像源conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
# 恢复默认设置conda config --remove-key channels避坑指南
- 不要同时添加多个镜像源!(会引发依赖冲突)
- 遇到SSL证书错误时,试试
conda update conda - 安装特定版本时建议指定channel:
conda install pytorch==1.7.1 -c pytorch
Pip 与 Conda 国内换源指南
/blog/posts/成长日记/python/pip-conda-mirror/ Some information may be outdated