我们在使用Python开发是,免不了要安装各种依赖包,官方推荐命令如下:
#pip install package
使用上述命令安装依赖包时,默认的下载源pypi.python.org/pypi 下载,服务器在国外自然比减慢。因此笔者在这里总结一些常用的镜像源。
1 清华:https://pypi.tuna.tsinghua.edu.cn/simple
2.豆瓣:https://pypi.douban.com/simple/
3.阿里云:https://mirrors.aliyun.com/pypi/simple/
4.中国科技大学:https://pypi.mirrors.ustc.edu.cn/simple/
5.华中理工大学:https://pypi.hustunique.com/
使用方法:
#pip install package -i https://pypi.tuna.tsinghua.edu.cn/simple
对于一般使用者来说,在安装依赖包时指定镜像源就可以,但命令太长,使用起来也不方便,下面就介绍如何修改安装源。
1普通Python环境
1.1 Linux系统
在用户home目录下执行以下命令:
$mkdir ~/.pip
$cd ~/.pip
$vi pip.conf
按i进入编辑模式,输入以下内容:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
1.2 Windows系统
进入C:\Users\username,新建pip文件夹,然后进入该文件夹,新建pip.ini文件,输入一下内容:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
2 Anaconda 集成开发环境
2.1 Linux系统
在home目录下新建.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/cloud/conda-forge/
ssl_verify: true
2.2 Windows系统
进入C:\Users\username,新建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/cloud/conda-forge/
ssl_verify: true
【注】Linux/Windows 对应目录的 .condarc 里修改也是可以的。.condarc 以点开头,一般表示 conda 应用程序的配置文件,在用户的根目录 windows:C:\users\username\,linux:/home/username/
2.3删除镜像源/回复默认源
换回conda的默认源。这就简单了,直接删除channels即可。
conda config --remove-key channels
笔者这里使用的是清华源,目前清华开源镜像站和中科大开源镜像站均已发出公告表示已取得Anaconda授权,请大家放心使用!
欢迎访问我的网站:
BruceOu的哔哩哔哩
BruceOu的主页
BruceOu的博客
BruceOu的简书
接收更多精彩文章及资源推送,请订阅我的微信公众号: