Skip to content
On this page

方法一:通过文件资源管理器(推荐)

  1. 打开文件资源管理器,地址栏输入 %APPDATA% 回车,进入 C:\Users\<用户名>\AppData\Roaming
  2. 新建文件夹 pip
  3. 进入 pip,新建文本文件,重命名为 pip.ini(确保扩展名是 .ini
  4. 右键编辑,填入:
ini
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host = mirrors.aliyun.com

可以替换为其他镜像源:

  • 清华:https://pypi.tuna.tsinghua.edu.cn/simple
  • 中科大:https://pypi.mirrors.ustc.edu.cn/simple

方法二:通过 PowerShell 命令创建

powershell
# 创建 pip 文件夹(如果不存在)
New-Item -ItemType Directory -Force -Path "$env:APPDATA\pip"

# 创建并写入 pip.ini 文件
@"
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com
"@ | Out-File -FilePath "$env:APPDATA\pip\pip.ini" -Encoding utf8

验证配置是否生效

powershell
pip config list

看到输出中包含你设置的 index-url 即表示配置成功。