Poetry

Definition

Poetry manages Python dependencies, virtual environments, and packaging through a single declarative pyproject.toml, replacing the older requirements.txt + pip + venv workflow.


Core Ideas

Virtual environments

Poetry creates and manages a per-project virtual environment automatically. The easiest way to activate it is a nested shell:

poetry shell

Run one-off commands inside the environment with poetry run <cmd>.

Migrating from requirements.txt

Import an existing project’s pinned dependencies into Poetry in one line:

poetry add $(grep -v '^#' requirements.txt)

(The grep -v '^#' strips comment lines.) From then on, poetry add / poetry remove update pyproject.toml and the lock file.


Relationships


References

  • Poetry — Basic Usage
  • Import requirements.txt using Poetry (Stack Overflow)