# PyPI 软件仓库

> 可调整选项：
> - 镜像地址：`https://mirrors.cernet.edu.cn/pypi`
> - sudo：`开启`


> 本站收录所有共享帮助文档；文档存在不代表浙江大学镜像站当前提供该镜像。请查阅 https://mirrors.zju.edu.cn/mirrorz.json 确认当前目录与状态。
> 下列命令使用上述选项，请根据实际系统版本选择；未填写的文本选项需要在原文页面补充。

PyPI 镜像在每次同步成功后间隔 5 分钟同步一次。

### pip

#### 临时使用

```bash
pip install -i https://mirrors.cernet.edu.cn/pypi/web/simple some-package
```

注意，`simple` 不能少。
pip 要求使用 `https` ，因此需要 `https` 而不是 `http`

#### 设为默认

升级 pip 到最新的版本后进行配置：

```bash
python -m pip install --upgrade pip
pip config set global.index-url https://mirrors.cernet.edu.cn/pypi/web/simple
```

如果您到 pip 默认源的网络连接较差，临时使用本镜像站来升级 pip：

```bash
python -m pip install -i https://mirrors.cernet.edu.cn/pypi/web/simple --upgrade pip
```

#### 配置多个镜像源

如果您想配置多个镜像源平衡负载，可在已经替换 `index-url` 的情况下通过以下方式继续增加源站：

```bash
pip config set global.extra-index-url "<url1> <url2>..."
```

请自行替换引号内的内容，源地址之间需要有空格

例如

```bash
pip config set global.extra-index-url "https://mirrors.cernet.edu.cn/pypi/web/simple"
```

### PDM

通过如下命令设置默认镜像：

```bash
pdm config pypi.url https://mirrors.cernet.edu.cn/pypi/web/simple
```

### Poetry

通过以下命令为单个项目设置首选镜像：

```bash
poetry source add --priority=primary mirrors https://mirrors.cernet.edu.cn/pypi/web/simple/
```

通过以下命令为单个项目设置补充镜像：

```bash
poetry source add --priority=supplemental mirrors https://mirrors.cernet.edu.cn/pypi/web/simple/
```

Poetry 尚未支持全局设置镜像。参考 [issue 1632](<https://github.com/python-poetry/poetry/issues/1632>)。

使用全局镜像的临时方案是将 Poetry 的安装器切换回 pip，如下所示。但该方式会在将来的版本中停止支持，参考 [PR 7356](<https://github.com/python-poetry/poetry/pull/7356>)。

```bash
poetry config experimental.new-installer false
```

### Astral uv

- Linux/Unix：在 `~/.config/uv/uv.toml` 或者 `/etc/uv/uv.toml`
- Windows：在 `%AppData%\uv\uv.toml` 或者 `%ProgramData%\uv\uv.toml`

填写下面的内容：

```toml
[[index]]
url = "https://mirrors.cernet.edu.cn/pypi/web/simple"
default = true
```

详情参考[官方配置文件文档](<https://docs.astral.sh/uv/configuration/files/>)。

## Homebrew

本节主要供 [Homebrew 帮助](<https://mirrors.zju.edu.cn/docs/homebrew/>)使用。

```bash
export HOMEBREW_PIP_INDEX_URL="https://mirrors.cernet.edu.cn/pypi/web/simple"
```

---

许可：[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)
文档索引：https://mirrors.zju.edu.cn/llms.txt
如仅限浙大校内网络访问，可将 mirrors.cernet.edu.cn 替换为 mirrors.zju.edu.cn。
