修改Pip配置永久添加镜像

前言

        pip下载第三方库时下载很慢,有时需要添加镜像。但每次命令行中添加镜像很麻烦,于是可以通过修改配置文件,实现pip下载时自动使用镜像。

步骤

        在用户目录下,创建pip文件,在文件里添加pip.ini文件,输入清华镜像:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/

检验

pip config list

        添加成功

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用pip添加清华镜像源有两种方式:临时使用和永久配置。 临时使用清华镜像源的方法是在执行pip安装命令的时候指定清华镜像源的URL。例如,要下载名为xxx的包,可以使用以下命令: ``` pip install -i https://pypi.tuna.tsinghua.edu.cn/simple xxx ``` 其中,https://pypi.tuna.tsinghua.edu.cn/simple是清华镜像源的URL,xxx是需要下载的包的名字。这种方式只在当前命令中使用清华镜像源,不会对默认服务器配置产生影响。 永久配置清华镜像源的方法有两种。第一种是通过执行以下命令来永久替换服务器为清华镜像源: ``` pip3 install pip -U pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple ``` 其中,"pip install pip -U" 是用于执行升级pip的命令,将pip版本更新到最新。"pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple" 是用于设置全局的index-url,将服务器配置为清华镜像源。这样,在执行pip安装命令时,就会默认使用清华镜像源进行下载。 第二种方法是通过修改pip配置文件来永久设置清华镜像源。打开用户目录下的pip配置文件(Linux/macOS为~/.pip/pip.conf,Windows为C:\Users\用户名\pip\pip.ini),将以下内容添加配置文件中: ``` <span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [pip添加清华镜像源](https://blog.csdn.net/eefresher/article/details/89606866)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [【Pythonpip配置清华镜像源](https://blog.csdn.net/yyj3900636/article/details/122744249)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值