pdm
文章目录
代码存放路径 和 文件布局
参考:
- src layout vs flat layout — Python Packaging User Guide
- pdm-backend src layout: Build configurations - PDM-Backend
默认行为:
- 如果没有
src文件夹, pdm 认为项目是 flat layout 即:
- pdm 支持 src layout
pdm 支持 flat layout
- 注意,不要生成 src 文件夹
venv 管理
使用 conda
创建
1pdm venv create -w conda -n venv38 3.8activate
1 2 3 4 5 6 7eval `pdm venv activate` # 验证有效 # linux 上 `pdm venv activate` # 验证有效 # pwsh 上 iex $(pdm venv activate)deactivate
1conda deactivate
pypi pip 源
| |
安装 torch 方法
指定 cuda index source
参考:
验证有效方法:
| |
- like:
pip install torch --index-url https://download.pytorch.org/whl/cu118
安装源配置
参考:
--index-url和--find-links区别
设置优先级
| |
like pip –index-url (-i)
要点:
- 使用
type = "index"
举例:
pytorch 2.1.1 + cuda 11.8 安装:
pip install torch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1 --index-url https://download.pytorch.org/whl/cu118
pdm 等价命令:
- 在设置好 pyproject.toml 后
pdm add torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0
导出到 requirements.txt 方法
pdm export --format requirements --without-hashes
| |
导出成 requirements.txt 结果举例:
| |
like pip –find-links (-f)
要点:
- 使用
type = "find_links"
举例:
- paddlepaddle-gpu 安装:Run the following command to install
pdm add paddlepaddle-gpu==2.6.0.post117等价于python -m pip install paddlepaddle-gpu==2.6.0.post117 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html导出到 requirements.txt 方法
pdm export --format requirements --without-hashes
| |
导出结果举例:
| |
安装 cache
参考:
类似 pnpm, 中心化安装,具体的 venv 会软链接到实际的 cache 位置
启用方法:
| |
文章作者
上次更新 2025-09-24 (360d44c)