Skip to main content

Getting Started with Poetry: A Python Package Manager

· One min read
ひかり
Main bloger

Installing Poetry

Install Poetry using pip. (It's also a good idea to upgrade pip at the same time.)

python -m pip install --upgrade pip
pip install poetry

Creating a Python Project with Poetry

1. Creating a New Python Project

To create a new Python project, run poetry new. A Python project template will be generated.

poetry new xxxxxxxx

2. Existing Python Project

If you already have a Python project, run poetry init to add the necessary configuration files for Poetry.

poetry init

Entering the Poetry Virtual Environment

Run poetry shell to start a shell in the Poetry virtual environment. You can use the packages added using Poetry.

poetry shell

Adding Packages to Poetry

You can add dependency packages using poetry add.

poetry add xxxxxxxx

Other Commonly Used Commands

  • poetry list: Displays a list of commands.
  • poetry build: Creates packages (.tar.gz, .whl).
  • poetry install: Installs dependency packages.
  • poetry publish: Publishes created packages to PyPI, etc.
  • poetry search: Searches for packages.
  • poetry run: Executes commands in the Poetry environment.
  • poetry show: Displays available packages.
  • poetry update: Executes dependency package updates.