pip 使用国内镜像源

该博客介绍了如何配置pip以使用阿里云和清华大学的PyPI镜像作为全局下载地址,并将这两个源添加到信任名单中,以避免安装Python包时出现安全警告或错误。通过运行指定的pip配置命令,可以设置index-url并更新trusted-host,从而顺利进行包的安装。文章提供了详细的配置步骤和检查设置的命令。
部署运行你感兴趣的模型镜像

pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/
添加到信任名单中:pip config set global.trusted-host mirrors.aliyun.com,

注:如果此前已经设置过,可以直接打开 %APPDATA%\pip\pip.ini 这个文件进行修改,如果此前没有设置过,这个文件是不存在的,需要用命令设置:

 清华:

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn

pip config list

 %APPDATA%\pip\pip.ini

[global]
index-url = http://pypi.mirrors.ustc.edu.cn/simple
trusted-host = pypi.mirrors.ustc.edu.cn

pip documentation
阿里云:
设置全局的下载地址:pip3 config set global.index-url http://mirrors.aliyun.com/pypi/simple/
添加到信任名单中:pip3 config set global.trusted-host mirrors.aliyun.com,要不然安装的时候会报错(
WARNING: 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 we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with ‘–trusted-host mirrors.aliyun.com’.
ERROR: Could not find a version that satisfies the requirement opencv-python
ERROR: No matching distribution found for opencv-python)
修改完查看一下:pip3 config list


原文链接:https://blog.youkuaiyun.com/huzing2524/article/details/115704208

 原文链接:https://blog.youkuaiyun.com/qq_41375318/article/details/106895836

您可能感兴趣的与本文相关的镜像

Python3.11

Python3.11

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

### 配置 pip 使用国内镜像源的方法 在 Python 开发中,使用 `pip` 安装第三方库时,默认的镜像源是官方的 PyPI 服务器。由于网络原因,国内用户可能会遇到下载速度慢或连接超时的问题。为了解决这些问题,可以通过配置 `pip` 使用国内镜像源来加速包的下载过程。 #### 1. 临时使用国内镜像源 如果只是想在某次安装时使用国内镜像源,可以在 `pip install` 命令后加上 `-i` 参数指定镜像源地址。例如,使用清华大学的镜像源安装 `requests` 库: ```bash pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simple ``` 这种方式只对当前命令生效,不会影响后续的 `pip` 操作。 #### 2. 永久配置国内镜像源 如果希望每次使用 `pip` 安装库时都自动使用国内镜像源,可以通过修改 `pip` 的配置文件来实现。具体步骤如下: - **Linux/macOS 用户**:在用户目录下创建或编辑 `.pip/pip.conf` 文件。 - **Windows 用户**:在用户目录下创建或编辑 `pip\pip.ini` 文件。 以阿里云镜像为例,配置文件内容如下: ```ini [global] index-url = https://mirrors.aliyun.com/pypi/simple/ [install] trusted-host = mirrors.aliyun.com ``` 保存文件后,`pip` 将会默认使用阿里云的镜像源进行包的安装和更新。 #### 3. 主流国内镜像源推荐 以下是一些常用的国内镜像源及其特点: - **清华大学镜像**:https://pypi.tuna.tsinghua.edu.cn/simple 同步频率为15分钟/次,由学术机构维护,适合科研场景。 - **阿里云镜像**:https://mirrors.aliyun.com/pypi/simple/ 提供企业级 SLA 保障,电信/移动网络延迟低于30ms。 - **华为云镜像**:https://repo.huaweicloud.com/repository/pypi/simple 具备金融级稳定性,支持 HTTP/3 协议,适合对稳定性有高要求的场景。 #### 4. 验证配置是否生效 配置完成后,可以通过以下命令查看当前 `pip` 的配置信息,确认镜像源是否已经生效: ```bash pip config list ``` 如果看到类似以下输出,则表示配置成功: ``` global.index-url='https://mirrors.aliyun.com/pypi/simple/' install.trusted-host=['mirrors.aliyun.com'] ``` 通过上述方法,可以有效提升 `pip` 安装包的速度,提升开发效率。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值