pip配置国内镜像(window11)

文章介绍了如何在Windows环境下创建pip配置文件,将阿里云、豆瓣、中国科技大学等国内镜像源添加到pip,以提高Python包的下载速度,并通过添加到环境变量使配置生效。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

常见云镜像

"pypi官方":"https://pypi.org/simple/",
"清华大学": "https://pypi.tuna.tsinghua.edu.cn/simple/",
"中国科技大学": "https://pypi.mirrors.ustc.edu.cn/simple/",
"豆瓣": "https://pypi.douban.com/simple/",
"网易": "https://mirrors.163.com/pypi/simple/",
"阿里云": "https://mirrors.aliyun.com/pypi/simple/",
"华为云": "https://repo.huaweicloud.com/repository/pypi/simple",
"腾讯云": "https://mirrors.cloud.tencent.com/pypi/simple/"

创建pip配置文件

在家目录C:\Users\zhou\创建pip文件夹
进入pip文件夹C:\Users\zhou\pip,并创建文件pip.ini
写入并保存以下内容:

[global]
timeout=40
index-url=http://mirrors.aliyun.com/pypi/simple/
extra-index-url=
        http://mirrors.aliyun.com/pypi/simple/
        http://pypi.douban.com/simple
        http://pypi.mirrors.ustc.edu.cn/simple/
	  	https://pypi.tuna.tsinghua.edu.cn/simple/
 
[install]
trusted-host=
        mirrors.aliyun.com
        pypi.douban.com
        pypi.mirrors.ustc.edu.cn
	  	pypi.tuna.tsinghua.edu.cn

添加pip配置文件到环境变量

环境变量
pip路径

配置完成后,cmd查看是否生效

使用命令pip config list,可以看到配置文件生效

C:\Users\zhou>pip config list
global.extra-index-url='\nhttp://mirrors.aliyun.com/pypi/simple/\nhttp://pypi.douban.com/simple\nhttp://pypi.mirrors.ustc.edu.cn/simple/\nhttps://pypi.tuna.tsinghua.edu.cn/simple/'
global.index-url='http://mirrors.aliyun.com/pypi/simple/'
global.timeout='40'
install.trusted-host='\nmirrors.aliyun.com\npypi.douban.com\npypi.mirrors.ustc.edu.cn\npypi.tuna.tsinghua.edu.cn'
### 配置 Hugging Face 的中国镜像站点 为了在 Windows 系统中配置 Hugging Face 的中国镜像站点,可以采用如下方法: 环境变量设置能够帮助指定默认的 Hugging Face Hub URL。这使得即使在网络条件不佳的情况下也能顺利获取模型和其他资源。 #### 设置临时环境变量 打开命令提示符窗口并输入以下指令来暂时改变 `TRANSFORMERS_CACHE` 和 `HF_DATASETS_OFFLINE` 变量指向国内镜像地址[^2]。 ```batch set HF_ENDPOINT=https://hf-mirror.com/api/ ``` 此方式仅对当前命令行会话有效,在关闭终端之后便会失效。 #### 修改 Python 脚本中的导入路径 对于更持久性的解决方案,可以在每次调用库之前调整其内部参数。例如,在运行脚本前加入几行代码以更改远程仓库链接至中国的镜像服务器[^3]。 ```python import os os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com/api/' ``` 上述做法适用于那些希望保持原有安装不变而又能享受加速下载体验的人群。 #### 利用 pip 安装来自镜像源的包 如果打算利用pip工具从特定位置安装Python软件包,则可通过下面的方式指定阿里云PyPI镜像作为索引URL[^4]。 ```batch pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ pip install transformers ``` 需要注意的是,这些操作均假设读者已经具备基本的编程技能以及熟悉Windows系统的常规操作流程。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值