【Python】pip 换源

Python 使用 pip 下载 “包” 默认使用官方的下载源,服务器在国外,国内下载一般比较慢,可以更换国内下载源解决。

一、源

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
阿里云 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/

二、临时更换

pip install 包名 –i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

三、永久方法

1、win + r 输入 %USERPROFILE% 进入用户文件夹(C:\User\用户名)
2、打开 pip 文件夹(没有则创建)打开 pip.ini 文件(没有则创建)
3、输入如下内容并保存

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

文件路径“C:\Users\用户名\pip\pip.ini”

四、常见问题

1、域名不可信

WARNING: The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.douban.com'.
解决方式:
文件则加上 trusted-host=镜像站域名
临时则加上 --trusted-host 域名

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值