Python PDM Project
Python型产品数据管理项目
https://pdm.fming.dev/latest/
Https://pdm.fming.dev/latest/
https://github.com/pdm-project/pdm
Https://github.com/pdm-project/pdm
My Problem
我的问题
In context below I want to activate the in-project virtual environment automatically whenever the directory changes to inclued the path ~/pydev/pdm-test
.
在下面的上下文中,每当目录更改为包含路径~/pydev/pdm-test时,我希望自动激活项目中的虚拟环境。
Tree View of PDM Test Folder
《产品数据管理测试》文件夹的树状视图
$ 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
Manual Activation of Virtual Environment (this works)
手动激活虚拟环境(这是可行的)
$ eval $(pdm venv activate in-project)
$val$(pdm venv在项目内激活)
Virtual Environment Autodetection
虚拟环境自动检测
https://pdm.fming.dev/latest/usage/venv/
Https://pdm.fming.dev/latest/usage/venv/
When no interpreter is stored in the project config or PDM_IGNORE_SAVED_PYTHON env var is set, PDM will try to detect possible virtualenvs to use:
- venv, env, .venv directories in the project root
- The currently activated virtualenv
Question - Where is the "project config" file and how do I edit this file or use a pdm command to enable virtual environment autodetection?
问题--“项目配置”文件在哪里?如何编辑该文件或使用pdm命令启用虚拟环境自动检测?
更多回答
优秀答案推荐
The python path is stored in the project config file .pdm.toml
, view it and remove the corresponding line to clear the python path. You can also do it with command line: pdm config -ld python.path
Python路径存储在项目配置文件.pdm.toml中,查看它并删除相应的行以清除python路径。您也可以使用命令行执行此操作:pdm config-ld python.path
I don't know a straight forward way to auto-activate the venv in the current shell.
我不知道有什么直接的方法可以自动激活当前外壳中的venv。
Where is the "project config" file
.pdm-python
Inside the project root
.pdm-项目根目录内的python
how do I edit this file or use a pdm command to enable virtual
environment autodetection?
auto-detection works by default, what is meant by auto-detection is that if you run any pdm command, it will use that venv, which is normally .venv in the project root, auto-activation is a different topic.
自动检测在默认情况下工作,自动检测的意思是,如果您运行任何pdm命令,它将使用venv,它通常是项目根目录中的.venv,自动激活是另一个主题。
Update: Auto-Activation
in ~/.bashrc, ~/.zshrc
更新:~/.bashrc、~/.zshc中的自动激活
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
}
Hope that helps
希望这能有所帮助
更多回答
I tried PDM
briefly ... then moved on ... because I could not see any advantages. On Debian-based host systems I now install python to each project folder using pyenv
and direnv
. This provides isolation and seems to use less disk space in my use cases.
我曾短暂地尝试过产品数据管理。然后继续前进..。因为我看不出有什么好处。在基于Debian的主机系统上,我现在使用pyenv和direnv将python安装到每个项目文件夹中。这提供了隔离,在我的用例中似乎使用了更少的磁盘空间。
我是一名优秀的程序员,十分优秀!