← 返回命令列表

Linux command

poetry-init 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Initialize interactively

poetry init

Non-interactive with defaults

poetry init -n

Specify name and description

poetry init --name [myproject] --description "[A cool project]"

Add dependencies during init

poetry init --dependency [requests] --dev-dependency [pytest]

Pin a Python version

poetry init -n --python "[^3.11]"

说明

poetry init creates a new pyproject.toml in the target directory describing the project's metadata and dependencies. The interactive flow walks through the project name, version, author, license, Python constraint, and any initial runtime/dev dependencies, validating package names against PyPI as you go. It does not create a virtual environment, install dependencies, or write a lock file — run poetry install afterwards for that.

参数

-n, --no-interaction
Skip the interactive prompts; uses defaults for any value not provided.
--name _name_
Package name (defaults to the current directory name).
--description _text_
Package description.
--author _author_
Author in "Name <email>" format. Repeatable.
--license _spdx_
SPDX license identifier (e.g. MIT, Apache-2.0).
--python _constraint_
Python version constraint (e.g. ^3.11, >=3.10,<4).
--dependency _name@version_
Add a runtime dependency. Repeatable.
--dev-dependency _name@version_
Add a development dependency. Repeatable.
--directory _path_
Run init in a different directory.
--help
Display help.

FAQ

What is the poetry-init command used for?

poetry init creates a new pyproject.toml in the target directory describing the project's metadata and dependencies. The interactive flow walks through the project name, version, author, license, Python constraint, and any initial runtime/dev dependencies, validating package names against PyPI as you go. It does not create a virtual environment, install dependencies, or write a lock file — run poetry install afterwards for that.

How do I run a basic poetry-init example?

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

What does -n, --no-interaction do in poetry-init?

Skip the interactive prompts; uses defaults for any value not provided.