Linux command
pdm 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Initialize a new project
pdm init
Add a dependency
pdm add [requests]
Add a development dependency
pdm add -d [pytest]
Install all dependencies
pdm install
Update dependencies
pdm update
Run a command in environment
pdm run [python] [script.py]
List installed packages
pdm list
Build package
pdm build
说明
pdm is a Python package manager following PEP standards. It manages dependencies, virtual environments, and builds using pyproject.toml. pdm init creates a new project with pyproject.toml. It detects or creates a Python interpreter and optionally initializes a virtual environment. Dependencies are declared in pyproject.toml and locked in pdm.lock. add modifies both; install reads the lock file. Dependency groups separate dev, test, and optional dependencies. PDM historically supported PEP 582 (__pypackages__) as an alternative to virtual environments, but PEP 582 was rejected in 2023; modern PDM defaults to virtualenvs. Local-package mode can still be enabled with pdm config python.use_venv false for users who prefer it. pdm run executes commands with the project environment active. Scripts defined in pyproject.toml under tool.pdm.scripts provide shortcuts. Build and publish follow PEP 517/518. pdm build creates wheels and sdists; pdm publish uploads to PyPI.
参数
- -d, --dev
- Development dependency.
- -G, --group _name_
- Dependency group.
- -L, --lockfile _file_
- Custom lock file path.
- --no-sync
- Don't sync after adding.
- --no-lock
- Skip lock file update.
- --prod, --production
- Exclude dev dependencies.
- -p, --project _path_
- Project directory.
- -v, --verbose
- Increase verbosity.
- -q, --quiet
- Suppress output.
FAQ
What is the pdm command used for?
pdm is a Python package manager following PEP standards. It manages dependencies, virtual environments, and builds using pyproject.toml. pdm init creates a new project with pyproject.toml. It detects or creates a Python interpreter and optionally initializes a virtual environment. Dependencies are declared in pyproject.toml and locked in pdm.lock. add modifies both; install reads the lock file. Dependency groups separate dev, test, and optional dependencies. PDM historically supported PEP 582 (__pypackages__) as an alternative to virtual environments, but PEP 582 was rejected in 2023; modern PDM defaults to virtualenvs. Local-package mode can still be enabled with pdm config python.use_venv false for users who prefer it. pdm run executes commands with the project environment active. Scripts defined in pyproject.toml under tool.pdm.scripts provide shortcuts. Build and publish follow PEP 517/518. pdm build creates wheels and sdists; pdm publish uploads to PyPI.
How do I run a basic pdm example?
Run `pdm init` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -d, --dev do in pdm?
Development dependency.