IntelliJ IDEA 2022.1 Help

Configure a Poetry environment

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.

To use Poetry in IntelliJ IDEA, you need to install it on your machine and create a specific Python environment.

Install Poetry

  1. Open a terminal window (PowerShell on Windows) and execute the following command that is specific to your operating system:

    curl -sSL | python -

    (Invoke-WebRequest -Uri -UseBasicParsing).Content | python -

    curl -sSL | python -

  2. Verify installation in the Poetry bin directory:

    Path: $HOME/.poetry/bin

    Example: /Users/jetbrains/.poetry/bin/poetry

    Path: %USERPROFILE%\.poetry\bin

    Example: C:\Users\jetbrains\.poetry\bin\poetry.bat

    Path: $HOME/.poetry/bin

    Example: /home/jetbrains/.poetry/bin/poetry

Refer to the Poetry Installation Instructions for more details.

These directories are automatically added to the $PATH variable, so that IntelliJ IDEA can pick it when creating a Poetry virtual environment.

Create a Poetry environment

  1. Ensure that the Python plugin is installed and enabled.

  2. Navigate to File | Project Structure Ctrl+Alt+Shift+S.

    Adding a new SDK
  3. In the Project Structure dialog, select SDKs under the Platform Settings section, click Add a new SDK, and from the popup menu, choose Python SDK.

    Adding a new Python SDK
  4. In the left-hand pane of the Add Python Interpreter dialog, select Poetry Environment. The following actions depend on whether the virtual environment existed before.

    creating a poetry environment

    If Poetry Environment is selected:

    1. Select the base Python interpreter from the list, or click Virtual environment location and find its location in your file system.

    2. If IntelliJ IDEA has not discovered the Poetry path, click Show Poetry path near Poetry executable and navigate to its location. Then click OK in the explorer window to add it to the field.

    If Existing environment is selected:

    1. Expand the Interpreter list and select any of the existing Poetry environments. Alternatively, click Select an interpreter and specify a path to it.

  5. Click OK to complete the task.

When you configure a new Poetry environment, IntelliJ IDEA adds two files to your workspace:

  • pyproject.toml: specifies the project requirements

  • poetry.lock: records changes in the projects requirements

Each time you modify the pyproject.toml file, IntelliJ IDEA notifies you and offers two actions: to record the changes in the poetry.lock file or to record the changes and install the unsatisfied requirements.

Last modified: 31 March 2022