pip 和 Conda 镜像站配置
如果你经常使用 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)软件包的软件存储库。
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 的第三方包。
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
中产生一个隐藏文件 .condarc
(C:\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
配置一样
最新文章
- 深入理解javascript原型和闭包(6)——继承
- 使用JDOM操作XML
- 如何使用JDBC实现数据访问对象层(DAO)
- 2016年iOS技术圈回顾
- 第 29 章 CSS3 弹性伸缩布局[中]
- 位置式PID与增量式PID算法
- oracle 查看锁表情况并处理锁表
- DB2命令大全
- Android res资源文件夹的知识积累
- Jquery 进度条集锦
- Python BeautifulSoup4 使用指南
- No resource found that matches the given name 'android:WindowTitle'
- jquery实现显示和隐藏toggle()方法的使用
- 201521123106 《Java程序设计》第6周学习总结
- MarkDown的快速入门
- 源码安装pipelineDB之CentOS7
- python: 爬取[博海拾贝]图片脚本
- AndroBench手机性能测试
- 版本控制git第一篇
- BZOJ1264 [AHOI2006]基因匹配Match 动态规划 树状数组