> ## Content Index
> Fetch the complete content index at: https://sgpublic.xyz/llms.txt
> Use this file to discover other available public pages before exploring further.

# 使用 pixi 配置阿里 PPU 环境
- URL: https://sgpublic.xyz/p/2026/04/6aac9cb1810a48000153361b/
- Published: 2026-04-28T04:31:58.000Z
- Updated: 2026-09-18T04:59:25.000Z
- Author: Haven Madray
- Tags: AI 与算力, NVIDIA/CUDA, #wp-post

### 前言

pixi 基于 uv 开发，拥有与 uv 一样的速度，还支持一系列额外的功能，例如：

- 完全替代 conda，兼容 conda 的所有生态，可以在虚拟环境中安装 ffmpeg、cuda-toolkit 等系统依赖，当然也可以安装 python；
- 多语言环境，不仅可以管理 python，还能管理 Java、Node.js 等；
- 任务系统，类似 npm run，可以将繁琐的命令通过 task 一键启动。

所以十分推荐使用 pixi 一站式代替 conda、poetry、uv、venv 等所有工具。

### 食用方法

首先安装 pixi 请参照官方教程：[https://pixi.prefix.dev/latest/installation/](https://pixi.prefix.dev/latest/installation/?ref=sgpublic.xyz)

安装完成后，使用以下命令创建 pixi 项目：

```bash
pixi init

```

这个命令会在当前目录创建文件 `pixi.toml`，内容大致如下：

```toml
[workspace]
authors = ["Haven Madray <xxx@gmail.com>"]
channels = ["conda-forge"]
name = "test"
platforms = ["linux-64"]
version = "0.1.0"

[tasks]

[dependencies]

```

我这里环境提供的 PPU 的源需要登录使用，使用以下命令保存认证信息：

```bash
pixi auth login pypi.aistack-dev.com --username xxx --password xxx

```

这样可以避免把认证信息保存到项目里。

接下来需要添加 python 和 setuptools：

```bash
pixi add 'python>=3.12,<3.13'
pixi add 'setuptools>=77'

```

然后给 `pixi.toml` 追加如下内容：

```toml
[feature.cuda.system-requirements]
cuda = "12.9"

[feature.cuda.dependencies]
# 适用于 cuda 环境的系统依赖
cuda-toolkit = ">=12.9,<12.10" # 使用 cuda-toolkit 12.9
cudnn = ">=9,<10" # 使用 cudnn 9

[feature.cuda.pypi-dependencies]
# 适用于 cuda 环境的 python 依赖
torch = { version = ">=2.9.0,<2.10", index = "https://download.pytorch.org/whl/cu129" } # 从官方源中添加适用于 cuda 12.9 的 torch
torchvision = { version = ">=0.24.0, <0.25", index = "https://download.pytorch.org/whl/cu128" } # 从官方源中添加适用于 cuda 12.9 的 torchvision
onnxruntime-gpu = ">=1.23.0, <1.24" # 添加适用于 cuda 的 onnxruntime

[feature.cpu.pypi-dependencies]
# 适用于 cpu 环境的 python 依赖
torch = { version = ">=2.9.0,<2.10", index = "https://download.pytorch.org/whl/cpu" } # 从官方源中添加适用于 cpu 的 torch
torchvision = { version = ">=0.24.0, <0.25", index = "https://download.pytorch.org/whl/cpu" } # 从官方源中添加适用于 cpu 的 torchvision
onnxruntime = ">=1.23.0, <1.24" # 添加适用于 cpu 的 onnxruntime

[feature.ppu.pypi-dependencies]
# 适用于 ppu 环境的 python 依赖
torch = { version = "==2.9.0+ppu2.0.0.oe", index = "https://pypi.aistack-dev.com/repository/cu129_index/simple/" } # 从 ppu 源中添加适用于 ppu 的 torch
torchvision = { version = "==0.24.0+ppu2.0.0", index = "https://pypi.aistack-dev.com/repository/pypi_index/simple/" } # 从 ppu 源中添加适用于 ppu 的 torchvision
onnxruntime-gpu = { version = "==1.23.2+ppu2.0.0.oe", index = "https://pypi.aistack-dev.com/repository/pypi_index/simple/" } # 从 ppu 源中添加适用于 ppu 的 onnxruntime

[pypi-options]
no-build-isolation = ["torchvision"] # 解决 torchvision 安装失败

[environments]
cpu = { features = ["cpu"] } # 适用于 cpu 的环境
cuda = { features = ["cuda"] } # 适用于 cuda 的环境
default = { features = ["ppu"] } # 项目默认使用 ppu

```

使用以下命令安装环境依赖：

```bash
pixi install # 安装默认环境，即 ppu
pixi install -e cuda # 安装适用于 cuda 的环境

```

关于让 pixi 与 PyCharm 联动，请参阅官方文档：[JetBrains - Pixi](https://pixi.prefix.dev/latest/integration/editor/jetbrains/?ref=sgpublic.xyz#pycharm)