安装
1
| winget install -i astral-sh.uv
|
python版本管理
列举可安装版本
安装指定版本
装好的解释器放在 ~/.local/share/uv/python,无需 root,与系统 Python 无关
删除指定版本
1
| uv python uninstall 3.12
|
创建隔离环境
1
2
| uv init example --python 3.12
cd example
|
1
2
3
4
| cd example
uv python pin 3.12
uv init
uv venv
|
激活环境
1
| source .venv/bin/activate
|
1
| .venv\Scripts\Activate.ps1
|
安装包
1
| uv add torch==2.9.0+cu130 torchvision==0.24.0 torchaudio==2.9.0 --default-index https://download.pytorch.org/whl/cu130
|
测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| import torch
def check_torch_cuda():
print("✅ PyTorch 版本:", torch.__version__)
print("✅ PyTorch 内置 CUDA 版本:", torch.version.cuda)
print("✅ PyTorch 内置 cuDNN 版本:", torch.backends.cudnn.version())
if torch.cuda.is_available():
print("\n🔥 GPU 加速状态:已激活")
print("• 当前显卡型号:", torch.cuda.get_device_name(0))
print("• 可用 GPU 数量:", torch.cuda.device_count())
print("• 显存总容量: {:.2f} GB".format(
torch.cuda.get_device_properties(0).total_memory / 1e9))
else:
print("\n❌ GPU 加速状态:未检测到可用显卡")
if __name__ == "__main__":
check_torch_cuda()
|
退出隔离环境
复现环境