pip更改默认镜像源

在很多环境下,pip默认的镜像源下载速度会很慢或者直接无法使用,这时候我们可以临时指定镜像源,如:

pip install <package> -i <url>

这样通过 − i -i i 参数来临时指定下载的镜像源虽然能够解决问题,但每次加入过长的后缀十分麻烦。因此,我们需要修改pip的配置文件永久地更改pip的镜像源。
pip的配置文件在linux系统中为:

~/.pip/pip.conf

在windows系统中为:

C:\Users\{YourNanme}\AppData\Roaming\pip\pip.ini

若上述配置文件不存在,则手动创建。
也可通过下面的命令查看配置文件位置:

pip -v config list

找到pip的配置文件后,以阿里云镜像为例,修改文件内容为:

[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
trusted-host=mirrors.aliyun.com

保存配置文件,则完成了对pip默认镜像源的更换。

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
使用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 ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值