Configure a Poetry environment

Overview

Poetry is a tool that facilitates creating a Python virtual environment based on the project dependencies. You can declare the libraries your project depends on, and Poetry will install and update them for you.

Project dependencies are recorded in the pyproject.toml file that specifies required packages, scripts, plugins, and URLs. See the pyproject reference for more information about its structure and format.

Install Poetry

  1. Open Terminal (on macOS and Linux) or PowerShell (on Windows) and execute the following command:

curl -sSL https://install.python-poetry.org | python3 -
  1. On macOS and Windows, the installation script will suggest adding the folder with the poetry executable to the PATH variable. Do that by running the following command:

export PATH="/Users/tutorial/.local/bin:$PATH"

Don’t forget to replace tutorial with your username!

  1. To verify the installation, run the following command:

poetry --version

You should see something like Poetry (version 1.5.0).

Post-Install

By Default Poetry installs virtual environments in a subfolder of the user’s home directory. To change the default location to install in the projects current directory (.venv), set configuration option virtualenvs.in-project to true:

poetry config virtualenvs.in-project true

Also, it is possible to instruct Poetry to create its virtual environments in the project’s root directory via a poetry.toml in the root directory of the project:

[virtualenvs]
in-project = true