PDM - Python Development Master
PDM is a modern Python package and dependency manager that supports the latest PEP standards, including PEP 582 for local package directories. It offers robust dependency resolution, a unified `pyproject.toml` interface, and flexible virtual environment management. Currently at version 2.26.7, PDM maintains an active release cadence with frequent minor updates and bug fixes.
Warnings
- breaking PDM v2 introduced significant breaking changes from v1, including a new lock file format (`pdm.lock` instead of `Pipfile.lock`) and updates to CLI commands and configuration. Projects upgrading from PDM 1.x require migration.
- gotcha PDM primarily uses `pyproject.toml` for all project metadata and dependency management. Mixing PDM with legacy `requirements.txt`, `setup.py`, or `Pipfile` within the same project can lead to conflicts and unexpected behavior.
- gotcha PDM's default virtual environment location is typically global (`~/.local/share/pdm/venvs`). Users accustomed to `venv` or `Poetry` creating a `.venv` folder in the project root might be surprised. Project-local venvs can be enabled but require configuration.
- gotcha The commands `pdm install` and `pdm sync` have distinct behaviors. `pdm install` adds new packages and updates the `pdm.lock` file, while `pdm sync` only installs/updates dependencies specified in the existing `pdm.lock` file without modifying it. Misunderstanding this can lead to outdated lock files or unexpected dependency installations.
Install
-
pipx install pdm -
curl -sSL https://pdm.fming.dev/install.py | python3 -
Imports
- Core
from pdm.core import Core
Quickstart
# 1. Initialize a new PDM project
pdm init
# 2. Add a dependency
pdm add requests
# 3. Run a command within the project's environment
pdm run python -c "import requests; print('Requests is installed!')"
# 4. (Optional) Install development dependencies
pdm add pytest --dev
# 5. (Optional) Activate the virtual environment directly
pdm venv activate
# Then run: python -c "import requests; print('Requests is installed!')"
# deactivate # To exit the virtual environment