《修改pip默认数据源方法》
前言:
默认情况下我们 pip 使用的是国外的镜像,从国外网站下载第三方库,下载速度真的是非!常!慢!…
这里教新手们如何使用国内镜像快速下载第三方库。
一、临时 使用国内pypi镜像安装
格式:
pip + install + 第三方依赖包名称 + -i +
https://pypi.tuna.tsinghua.edu.cn/simple
例如:
pip install django -i https://pypi.tuna.tsinghua.edu.cn/simple
其他数据源:
阿里云[https://mirrors.aliyun.com/pypi/simple/](https://mirrors.aliyun.com/pypi/simple/) 豆瓣 [https://pypi.douban.com/simple/](http://pypi.douban.com/simple/) 清华大学 [https://pypi.tuna.tsinghua.edu.cn/simple/](https://pypi.tuna.tsinghua.edu.cn/simple/) 中国科学技术大学 [https://pypi.mirrors.ustc.edu.cn/simple/](http://pypi.mirrors.ustc.edu.cn/simple/)
二、永久 使用国内pypi镜像安装
1. Window平台安装方式:
① 新建 pip 配置文件夹,直接在user用户目录中创建一个名为 pip 的文件夹
② 在 pip 文件夹中创建一个名为 pip 的文本文件(后缀名由" .txt "改为 " .ini "),格式如下所示:
文件内容如下:[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] use-mirrors = true mirrors =https://pypi.tuna.tsinghua.edu.cn/simple trusted-host = pypi.tuna.tsinghua.edu.cn
trusted-host 此参数是为了避免麻烦,否则使用的时候可能会提示不受信任
2. Linux平台安装方式:
① 创建pip.conf文件
首先运行以下命令: cd ~/.pip # 运行此命令切换目录 如果提示目录不存在,自行创建一个(如果目录存在,可跳过此步),如下: mkdir ~/.pip cd ~/.pip
②在 .pip目录下创建一个 pip.conf 文件
touch pip.conf
③编辑 pip.conf 文件
先打开文件 sudo vi ~/.pip/pip.conf
④写入以下内容:
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host = https://pypi.tuna.tsinghua.edu.cn
trusted-host 此参数是为了避免麻烦,否则使用的时候可能会提示不受信任
3. 遇到的问题
warning:windows pip is configured with locations that require TLS/SSL,however the ssl modul....
解决办法:
①可将连接中的https改为http。如:
[global]
index-url = http://pypi.tuna.tsinghua.edu.cn/simple[install]
trusted-host = pypi.tuna.tsinghua.edu.cn
②Anaconda 环境变量未配置完全
环境遍历配置如下所示:
③需要下载SSL的MSL文件
参考链接:
https://blog.csdn.net/qq_44845794/article/details/107554809