当前位置: 首页 > news >正文

【pip】 的换源(临时换源和永久换源)

【pip】 的换源(临时换源和永久换源)

  • 一、临时换源
  • 二、永久换源
  • 三、Linux换源
  • 四、Windows换源

一、临时换源

临时换源只需要在pip安装包时,加上一个-i参数后接源的url即可:

临时换源:

清华源
pip3 install markdown -i https://pypi.tuna.tsinghua.edu.cn/simple阿里源
pip3 install markdown -i https://mirrors.aliyun.com/pypi/simple/腾讯源
pip3 install markdown -i http://mirrors.cloud.tencent.com/pypi/simple豆瓣源
pip3 install markdown -i http://pypi.douban.com/simple/

二、永久换源

清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple阿里源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/腾讯源
pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple豆瓣源
pip config set global.index-url http://pypi.douban.com/simple/换回默认源
pip config unset global.index-url

pip换源的方式
在使用Python安装包工具pip时经常会出现下载很慢的情况,这其中有很大一部分原因和pip的源有关,在我们安装python后,通常python解释器自带pip这个工具,但是这里pip是设置的默认源,也就是官方源:

https://pypi.org/simple,这个源在国内的下载速度是很慢的,所以我们为了提高包的下载速度我们可以通过换源来实现。

PYPI国内源路径
阿里云 
http://mirrors.aliyun.com/pypi/simple/豆瓣(douban) 
http://pypi.douban.com/simple/清华大学 
https://pypi.tuna.tsinghua.edu.cn/simple/中国科学技术大学 
http://pypi.mirrors.ustc.edu.cn/simple/

下载python中的包,这里使用的是清华源
pip3 install markdown -i https://pypi.tuna.tsinghua.edu.cn/simple

显然不是一个一劳永逸的方法,只有下少量包的时候有使用的场景,下面我要介绍永久换源的方法,通过这个方式换源,那么以后我们下载的包就可以全部从这个url中下载了,这样大大减轻了我们的工作量,明显比临时换源的方法更好。

三、Linux换源

永久换源(更换默认源)
Linux
根目录下创建/修改 ~/.pip/pip.confpip 配置文件;

进入文件新增/修改内容;

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
保存文件并退出;

四、Windows换源

Windows在 %HOMEPATH%\pip\pip.ini 中修改上面第二步的内容;(例如:C:\Users\Administrator\AppData\Roaming\pip\pip.ini)
保存文件退出;
常见问题
安装包的时候出现

Collecting beautifulsoup4
The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwise you may silence this warning and allow it anyways with ‘–trusted-host mirrors.aliyun.com’.
Could not find a version that satisfies the requirement beautifulsoup4 (from versions: )
No matching distribution found for beautifulsoup4

这是一个问题是在pip镜像升级报警,只需要添加信任源即可:

临时换源处理

pip install beautifulsoup4 --trusted-host mirrors.aliyun.com

更换默认源配置(一劳永逸)

[install]
trusted-host=pypi.douban.com
http://www.lryc.cn/news/470111.html

相关文章:

  • Kaggle 数据集dogs-vs-cats的错误
  • 【网络原理】网络地址转换----NAT技术详解
  • React怎么创建虚拟dom和挂载到页面
  • kafka-console-ui的简介及安装使用
  • git 的分支管理详解
  • w003基于Springboot的图书个性化推荐系统的设计与实现
  • 医院信息化与智能化系统(6)
  • 前端学习---(6)js基础--4
  • 241026-RHEL如何以root身份卸载Docker
  • iPhone当U盘使用的方法 - iTunes共享文件夹无法复制到电脑怎么办 - 如何100%写入读出
  • jenkins ssh 免密报错Host key verification failed.
  • 智能科学与技术(一级学科)介绍
  • iOS调试真机出现的 “__llvm_profile_initialize“ 错误
  • Android SELinux——neverallow问题处理(十六)
  • Vue 关于路由
  • 香港海洋投资启动创新海洋牧场,领航全球海洋经济
  • C/C++ 每日一练:二分查找
  • Linux基础IO--重定向--缓冲区
  • Conda 安装与使用指南
  • C++中获取硬盘ID的方法
  • OpenRTP 传输增加OpenRTPServer
  • 使用vue3+cesium+earthsdk+supermap实现通视分析(有版本报错问题)
  • python 轮子是什么
  • 农作物大豆病虫害识别分类数据集(猫脸码客第227期)
  • 如何在算家云搭建GPT-SOVITS(语音转换)
  • ThinkPad T480拆机屏幕改装:便携式显示器DIY指南
  • C++ (8) C++11及更新特性:探索魔法新领域
  • 【vue】Mammoth.js的使用:将.docx和doc 文件转换成HTML
  • HarmonyOS介绍 第一课习题答案
  • c/c++ stdcall cdel fastcall等函数调用约定说明