如果你经常使用 Python,那么你对 pip 和 Conda 一定不陌生,它们作为包管理器,可以非常方便的帮助我们下载需要的 Python 包,但是受限于大多 Python 包的服务器在国外,国内下载速度缓慢,因此需要配置镜像站提升下载速度。

一、pip 镜像站

1.pip 是什么

pip 是一个通用的 Python 包管理器,具有对 Python 包查找、下载、安装、卸载的功能。pip 已内置于 Python3.4 和 2.7 及以上版本中。pip 默认从 PyPI 中下载包,PyPI 全名为 Python Package Index,是 Python 的正式第三方(official third-party)软件包的软件存储库。

PyPI 官网

2.镜像站列表

name index-url trusted-host
阿里云 https://mirrors.aliyun.com/pypi/simple/ mirrors.aliyun.com
豆瓣 https://pypi.douban.com/simple/ pypi.douban.com
腾讯云 https://mirrors.cloud.tencent.com/pypi/simple/ mirrors.cloud.tencent.com
华为云 https://repo.huaweicloud.com/repository/pypi/simple/ repo.huaweicloud.com
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ pypi.tuna.tsinghua.edu.cn
北京外国语大学 https://mirrors4.bfsu.edu.cn/pypi/web/simple/ mirrors4.bfsu.edu.cn
PyPI https://pypi.org/ pypi.org

不同地区访问镜像站的速度可能不同,请自行选择合适的镜像站

中科大的 pip 和 Conda 镜像站会重定向到北京外国语大学镜像站,故不列举

3.如何配置

查看 pip 安装源信息

pip config list

①.临时使用

每次使用 pip 安装包时指定镜像站

pip install [package-name] -i [index-url] --trusted-host [trusted-host]

例如安装 tensorflow 时使用 阿里云 镜像站

pip install tensorflow -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

②.永久使用

全局使用镜像站,所有包都通过该镜像站下载

pip config set global.index-url [index-url]
pip config set install.trusted-host [trusted-host]

例如全局使用 阿里云 镜像站

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip config set install.trusted-host mirrors.aliyun.com

③.详细配置

Windows

全局使用镜像站后,会在 C:\Users\xxx\AppData\Roaming\pip 中产生一个 pip.ini 文件(C:\Users\xxx\AppData\Roaming\pip\pip.ini)来记录配置信息(如果不存在就自己创建),我们可以修改这个文件进行更详细的配置,下面有一个参考模板:

[global]
timeout = 600
index-url = https://mirrors.aliyun.com/pypi/simple/
extra-index-url = https://pypi.douban.com/simple/
https://pypi.org/ [install]
trusted-host = mirrors.aliyun.com
pypi.douban.com
pypi.org
  • timeout = 600:超时限制为 600 秒

Linux/macOS

全局使用镜像站后,会在用户根目录 ~ 中产生一个隐藏文件夹 .pip,其中的 pip.conf 文件(~/.pip/pip.conf)来记录配置信息(如果不存在就自己创建),具体内容和 Windows 配置一样

二、Conda 镜像站

1.Conda 是什么

Conda 是一个开源的软件包和环境管理系统,用于安装多个版本的软件包及其依赖关系,并在它们之间轻松切换。它的包管理与 pip 类似,可以用来管理 Python 的第三方包。

Conda 官网

2.镜像站列表

name channels
阿里云 https://mirrors.aliyun.com/anaconda/
清华大学 https://mirrors.tuna.tsinghua.edu.cn/anaconda/
北京外国语大学 https://mirrors.bfsu.edu.cn/anaconda/

不同地区访问镜像站的速度可能不同,请自行选择合适的镜像站

3.如何配置

查看 Conda 安装源信息

conda info

①.全局使用

conda config --add channels [channels]

例如全局添加 清华大学 镜像站

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.tuna.tsinghua.edu.cn/anaconda/pkgs/r/

②.详细配置

Windows

全局使用镜像站后,会在 C:\Users\xxx 中产生一个隐藏文件 .condarcC:\Users\xxx\.condarc)来记录配置信息(如果不存在就自己创建),我们可以修改这个文件进行更详细的配置,下面有一个参考模板:

channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
- https://mirrors.bfsu.edu.cn/anaconda/pkgs/main/
- https://mirrors.bfsu.edu.cn/anaconda/pkgs/free/
- https://mirrors.bfsu.edu.cn/anaconda/pkgs/r/
- defaults
ssl_verify: true
show_channel_urls: true
auto_activate_base: false

上述模板展示了 Conda 主要库的镜像源,Conda 附加库的源可以通过 镜像站列表 中的地址访问镜像站后自行添加,例如从 清华大学 镜像站中添加的 pytorch 源地址为 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

  • ssl_verify: true:开启 SSH 认证
  • show_channel_urls: true:安装包时,显示包的源地址
  • auto_activate_base: false:关闭自动进入 base 环境

Linux/macOS

全局使用镜像站后,会在用户根目录 ~ 中产生一个隐藏文件 .condarc~/.condarc)来记录配置信息(如果不存在就自己创建),具体内容和 Windows 配置一样

最新文章

  1. 深入理解javascript原型和闭包(6)——继承
  2. 使用JDOM操作XML
  3. 如何使用JDBC实现数据访问对象层(DAO)
  4. 2016年iOS技术圈回顾
  5. 第 29 章 CSS3 弹性伸缩布局[中]
  6. 位置式PID与增量式PID算法
  7. oracle 查看锁表情况并处理锁表
  8. DB2命令大全
  9. Android res资源文件夹的知识积累
  10. Jquery 进度条集锦
  11. Python BeautifulSoup4 使用指南
  12. No resource found that matches the given name 'android:WindowTitle'
  13. jquery实现显示和隐藏toggle()方法的使用
  14. 201521123106 《Java程序设计》第6周学习总结
  15. MarkDown的快速入门
  16. 源码安装pipelineDB之CentOS7
  17. python: 爬取[博海拾贝]图片脚本
  18. AndroBench手机性能测试
  19. 版本控制git第一篇
  20. BZOJ1264 [AHOI2006]基因匹配Match 动态规划 树状数组

热门文章

  1. 注册接口(数字字典和api接口)
  2. php 23种设计模型 - 组合模式(合成模式)
  3. 【UML】统一建模语言及工具
  4. LGP6146题解
  5. LGP4714题解
  6. C++中如何可以修改const函数内的成员变量的值?
  7. 给Windows系统免疫不再受恶意代码骚扰
  8. ssm配置推荐
  9. unicode和unicode编码
  10. 内置方法 __str__ __repr__