← 返回命令列表

Linux command

poetry-add 命令

安全

权限或系统影响较大,执行前请核对目标。

常用示例

Add a dependency

poetry add [package]

Add specific version

poetry add [package]@[1.0.0]

Add development dependency

poetry add --group dev [package]

Add from git

poetry add git+https://github.com/[user]/[repo].git

Add multiple packages

poetry add [package1] [package2]

说明

poetry add adds dependencies to pyproject.toml and installs them. It resolves version constraints and updates the lock file automatically.

参数

--group, -G _group_
Dependency group to add the package to (e.g., dev, test).
--dev, -D
Shortcut for `--group dev`.
--optional
Add as an optional dependency to an extra.
--dry-run
Output the operations without executing them.
--editable, -e
Add vcs/path dependencies as editable.
--extras, -E _extras_
Extras to activate for the dependency (multiple values allowed).
--source _source_
Name of the source to use to install the package.
--python _version_
Python version constraint for which the dependency must be installed.
--platform _platform_
Platforms for which the dependency must be installed.
--markers _markers_
Environment markers describing when the dependency should be installed.
--allow-prereleases
Accept prereleases.
--lock
Do not perform install; only update the lockfile.

FAQ

What is the poetry-add command used for?

poetry add adds dependencies to pyproject.toml and installs them. It resolves version constraints and updates the lock file automatically.

How do I run a basic poetry-add example?

Run `poetry add [package]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --group, -G _group_ do in poetry-add?

Dependency group to add the package to (e.g., dev, test).