如果你经常使用 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./repository/pypi/simple/ | repo. | 清华大学 | https://pypi.tuna./simple/ | pypi.tuna. | 北京外国语大学 | https://mirrors4./pypi/web/simple/ | mirrors4. | PyPI | https:/// |
|
不同地区访问镜像站的速度可能不同,请自行选择合适的镜像站
中科大的 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 = 600index-url = https://mirrors.aliyun.com/pypi/simple/extra-index-url = https://pypi.douban.com/simple/ https:/// [install]trusted-host = mirrors.aliyun.com pypi.douban.com
- 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./anaconda/ | 北京外国语大学 | https://mirrors./anaconda/ |
不同地区访问镜像站的速度可能不同,请自行选择合适的镜像站
3.如何配置查看 Conda 安装源信息 conda info
①.全局使用conda config --add channels [channels]
例如全局添加 清华大学 镜像站 conda config --add channels https://mirrors.tuna./anaconda/pkgs/main/conda config --add channels https://mirrors.tuna./anaconda/pkgs/free/conda config --add channels https://mirrors.tuna./anaconda/pkgs/r/
②.详细配置Windows全局使用镜像站后,会在 C:\Users\xxx 中产生一个隐藏文件 .condarc(C:\Users\xxx\.condarc)来记录配置信息(如果不存在就自己创建),我们可以修改这个文件进行更详细的配置,下面有一个参考模板: channels: - https://mirrors.tuna./anaconda/pkgs/main/ - https://mirrors.tuna./anaconda/pkgs/free/ - https://mirrors.tuna./anaconda/pkgs/r/ - https://mirrors.tuna./anaconda/cloud/pytorch/ - https://mirrors./anaconda/pkgs/main/ - https://mirrors./anaconda/pkgs/free/ - https://mirrors./anaconda/pkgs/r/ - defaultsssl_verify: trueshow_channel_urls: trueauto_activate_base: false
上述模板展示了 Conda 主要库的镜像源,Conda 附加库的源可以通过 镜像站列表 中的地址访问镜像站后自行添加,例如从 清华大学 镜像站中添加的 pytorch 源地址为 https://mirrors.tuna./anaconda/cloud/pytorch/
- ssl_verify: true:开启 SSH 认证
- show_channel_urls: true:安装包时,显示包的源地址
- auto_activate_base: false:关闭自动进入 base 环境
Linux/macOS全局使用镜像站后,会在用户根目录 ~ 中产生一个隐藏文件 .condarc(~/.condarc)来记录配置信息(如果不存在就自己创建),具体内容和 Windows 配置一样 来源: https://www.cnblogs.com/oranhext/p/py-mirrors.html
|