Python PDM项目
https://pdm.fming.dev/latest/
https://github.com/pdm-project/pdm
我的问题
在下面的上下文中,我想在目录更改为包含路径~/pydev/pdm-test
时自动激活项目内虚拟环境。
PDM测试文件夹树形视图
$ tree ~/pydev/pdm-test -aL 2
/home/joe/pydev/pdm-test
├── 0000-proj0000
│ ├── main.py
│ └── __pycache__
├── 0005-proj0005
├── 0010-proj0010
├── pdm.lock
├── .pdm.toml
├── pyproject.toml
└── .venv
├── bin
├── .gitignore
├── lib
└── pyvenv.cfg
手动激活虚拟环境(this works)
$ eval $(pdm venv activate in-project)
虚拟环境自动检测
https://pdm.fming.dev/latest/usage/venv/
当项目配置中没有存储解释器或设置了PDM_IGNORE_SAVED_PYTHON env var时,PDM将尝试检测可能使用的虚拟envs:
- 项目根目录下的venv、env、.venv目录
- 当前激活的虚拟环境
问题-"项目配置"在哪里?文件,以及如何编辑该文件或使用pdm命令启用虚拟环境自动检测?
python路径保存在工程配置文件.pdm.toml
中,查看并删除对应行,清空python路径。您也可以使用命令行:pdm config -ld python.path
我不知道在当前shell中自动激活venv的直接方法。
"项目配置"在哪里?文件
.pdm-python项目根目录
我如何编辑这个文件或使用pdm命令启用虚拟环境autodetection ?
自动检测默认工作,自动检测的意思是如果你运行任何PDM命令,它将使用venv,它通常是项目根目录下的。venv,自动激活是另一个主题。
更新:自动激活在~/。bashrc, (~/. zshrc
function cd {
builtin cd "$@"
# bash regex pdm-test / conditionally activate the venv in the current shell
if [[ "$PWD" =~ pdm-test ]]
then
eval $(pdm venv activate)
fi
}
希望有帮助