【简单-修改pip默认数据源方法】

《修改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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 如果你想在Python中更换pip,有几种方法可以实现。一种是通过在使用pip命令时添加-i参数来指定,例如:pip install package -i https://pypi.tuna.tsinghua.edu.cn/simple。这种方法是临时使用的,只对当前命令有效。\[2\]另一种方法是在配置文件中进行设置。你可以编辑pip的配置文件,在其中添加以下内容并保存:\[3\] \[global\] timeout = 6000 index-url = https://pypi.tuna.tsinghua.edu.cn/simple trusted-host = pypi.tuna.tsinghua.edu.cn 这样,pip就会使用清华作为默认。你也可以根据需要将index-url修改为其他的地址。\[3\]另外,你还可以参考一些相关的文章,如《数据分析的环境不会搭?看这里准没错!》和《Linux下pip使用国内》等,来获取更详细的操作步骤和注意事项。\[1\] #### 引用[.reference_title] - *1* *3* [Python pip所有方法](https://blog.csdn.net/qq_33254766/article/details/116540977)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Python 更改pip](https://blog.csdn.net/sea_snow/article/details/104892470)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值