Poetry is a modern dependency management and packaging tool for Python. It streamlines the process of installing, managing, and publishing Python packages, offering a more robust and user-friendly alternative to traditional tools like pip and virtualenv. By providing a single, unified interface for various aspects of Python project management, Poetry aims to simplify development workflows and ensure reproducible builds. This guide will walk you through the installation process for Poetry across different operating systems, along with essential configuration steps to get you started.
Installation on Different Operating Systems
Poetry offers straightforward installation methods tailored for Windows, macOS, and Linux. The recommended installation method utilizes a dedicated script that handles the setup and ensures Poetry is correctly integrated into your system.

Windows
For Windows users, the recommended installation method involves downloading and running an official installation script. This script is designed to handle all necessary configurations, including setting up environment variables.
- Download the Installation Script: Open your web browser and navigate to the official Poetry installation page. You can usually find this by searching for “Poetry Python installation.” Download the
install-poetry.pyscript. - Run the Installer: Open a command prompt or PowerShell window. Navigate to the directory where you downloaded the script. Execute the script using Python. It is crucial to use the Python interpreter that you intend to manage with Poetry. If you have multiple Python versions installed, ensure you are using the desired one.
bash
python install-poetry.py
- Verify Installation: After the script completes, it will inform you about any necessary steps, such as adding Poetry to your system’s PATH. In most cases, the script handles this automatically. To verify the installation, close and reopen your command prompt or PowerShell window to refresh environment variables. Then, run the following command:
bash
poetry --version
If Poetry is installed correctly, this command will display the installed version number. If you encounter an error stating thatpoetryis not recognized, you might need to manually add the Poetry installation directory to your system’s PATH environment variable. The installer usually provides instructions or the exact path to add.
macOS and Linux
On macOS and Linux, the installation process is very similar, leveraging a shell script for a clean and efficient setup.
- Download and Execute the Installation Script: Open your terminal and run the following command. This command downloads the official installation script and pipes it directly to
bashfor execution.
bash
curl -sSL https://install.python-poetry.org | bash
This command will download the latest stable version of Poetry and install it in a dedicated directory within your user’s home directory. - Update Your PATH: The installer will output instructions on how to add Poetry to your system’s PATH. This typically involves adding a line to your shell’s configuration file (e.g.,
~/.bashrc,~/.zshrc, or~/.profile). For example, it might suggest adding:
bash
export PATH="$HOME/.poetry/bin:$PATH"
After adding this line, you need to reload your shell configuration by either closing and reopening your terminal or by runningsource ~/.bashrc(or your relevant shell configuration file). - Verify Installation: Once your shell is reloaded, verify the installation by running:
bash
poetry --version
This command should display the installed version of Poetry.
Alternative Installation Methods
While the official scripts are the recommended approach, Poetry can also be installed using pipx or pip. However, these methods are generally discouraged for managing Poetry itself, as they can lead to dependency conflicts or make it harder to manage Poetry’s own environment.
- Using
pipx(Recommended Alternative):pipxis a tool for installing and running Python applications in isolated environments. It’s a good choice if you want to keep Poetry separate from your system’s Python installation.
bash
pipx install poetry
- Using
pip(Not Recommended for general use): Installing Poetry withpipdirectly is possible but can interfere with your project’s dependencies.
bash
pip install poetry
If you use this method, ensure you are installing it into a dedicated environment and not globally into your system Python.
Initial Configuration and Setup
Once Poetry is installed, a few initial configurations can enhance your development experience and ensure Poetry works optimally with your Python projects.
Choosing a Python Version
Poetry allows you to specify which Python versions your project is compatible with. When you initialize a new project using poetry new or poetry init, Poetry will prompt you to select a Python version or infer it from your system.
If you need to install additional Python versions to work with Poetry, consider using tools like pyenv (for macOS and Linux) or the Python launcher (py) on Windows. These tools make it easy to install and switch between multiple Python interpreters.
Poetry’s Configuration Directory
Poetry stores its configuration and cached packages in a specific directory. The default location varies by operating system:
- Linux/macOS:
~/.config/poetry/ - Windows:
%APPDATA%pypoetry
You can view and modify Poetry’s configuration using the poetry config command. For example, to see the current configuration:
poetry config --list
To change a specific setting, such as the cache directory:
poetry config cache-dir /path/to/your/custom/cache
This flexibility is useful for managing disk space or for developers working in environments with specific storage requirements.
Managing Poetry Plugins
Poetry has a plugin system that allows extending its functionality. For example, plugins can add support for different package managers or integrate with CI/CD tools.
To list installed plugins:
poetry plugin list
To install a new plugin:
poetry plugin add <plugin-name>
For instance, to install a plugin for managing pre-commit hooks:
poetry plugin add poetry-plugin-pre-commit
Always ensure you are installing plugins from trusted sources.
Using Poetry for Project Management
With Poetry installed and configured, you can now leverage its power to manage your Python projects.
Initializing a New Project
To create a new Python project managed by Poetry, use the poetry new command followed by your project’s name. This command creates a standard project structure, including a pyproject.toml file.
poetry new my-awesome-project
cd my-awesome-project
This will create a directory my-awesome-project with subdirectories for your source code and tests, along with a basic pyproject.toml.
Alternatively, if you have an existing project that you want to manage with Poetry, navigate to its root directory and run:
poetry init
This command will interactively guide you through creating a pyproject.toml file, asking for project metadata, dependencies, and development dependencies.
Adding and Managing Dependencies
The core of Poetry’s functionality lies in its dependency management. The pyproject.toml file serves as the single source of truth for your project’s dependencies.
Adding a Dependency

To add a new package to your project, use the poetry add command:
poetry add requests
This command will:
- Add
requeststo the[tool.poetry.dependencies]section in yourpyproject.toml. - Resolve the latest compatible version of
requestsand any of its transitive dependencies. - Install the dependencies into your project’s virtual environment.
- Update the
poetry.lockfile to lock down the exact versions of all installed packages, ensuring reproducible builds.
You can also specify version constraints:
poetry add numpy@^1.20.0 # Adds NumPy with a compatible version constraint
poetry add pandas@latest # Adds the latest version of Pandas
Adding Development Dependencies
Development dependencies are packages required for development but not for the runtime of your application (e.g., linters, testing frameworks). Use the --group dev or --group test flags (or custom group names) to manage them.
poetry add pytest --group dev
poetry add black --group dev
These dependencies will be listed under their respective groups in pyproject.toml.
Installing Dependencies
If you clone a project that uses Poetry, you can install all its dependencies by running:
poetry install
This command reads the poetry.lock file to install the exact versions of packages specified, ensuring consistency across different environments. If poetry.lock does not exist, Poetry will resolve and install dependencies based on pyproject.toml and then create the lock file.
Updating Dependencies
To update all dependencies to their latest compatible versions according to the constraints in pyproject.toml:
poetry update
To update a specific package:
poetry update requests
Poetry will update the specified package and its dependencies, re-resolve versions, and update poetry.lock.
Removing Dependencies
To remove a package from your project:
poetry remove requests
This command will remove the package from pyproject.toml and poetry.lock, and uninstall it from your environment.
Managing Virtual Environments
Poetry automatically creates and manages virtual environments for your projects. By default, these environments are stored in a central cache directory.
Activating a Virtual Environment
To activate the virtual environment associated with your project directly in your current shell, use:
poetry shell
This command starts a new shell session with the virtual environment activated. To exit, simply type exit.
Running Commands in the Virtual Environment
If you don’t want to activate the shell, you can run commands directly within Poetry’s managed environment using:
poetry run <command>
For example, to run a Python script:
poetry run python my_script.py
Or to execute a command provided by an installed package:
poetry run pytest
Displaying Environment Information
To see the path to the virtual environment Poetry is using for your project:
poetry env info
This command provides details about the Python interpreter, the environment path, and other relevant information.
Advanced Poetry Features
Poetry offers several advanced features that can further enhance your Python development workflow.
Publishing Packages
Poetry simplifies the process of packaging and publishing your Python libraries to repositories like PyPI.
- Build the Package: First, build your package into distributable formats (wheel and sdist) by running:
bash
poetry build
This command will create files in adist/directory within your project. - Configure PyPI Credentials: You’ll need to configure your API token for PyPI. The easiest way is using
poetry configor by setting environment variables.
bash
poetry config pypi-token.pypi <your-pypi-token>
Alternatively, you can add your token to~/.config/poetry/auth.tomlor set thePOETRY_PYPI_TOKENenvironment variable. - Publish the Package: Once built and configured, publish your package with:
bash
poetry publish
Poetry will upload the built distributions to PyPI.
Script Definitions
You can define custom scripts within your pyproject.toml file, allowing you to run common commands with a simple alias.
Add a [tool.poetry.scripts] section to your pyproject.toml:
[tool.poetry.scripts]
start = "my_package.main:run_app"
lint = "flake8 src"
Then, you can run these scripts using poetry run:
poetry run start
poetry run lint
Plugin Management
As mentioned earlier, Poetry’s plugin system is a powerful way to extend its capabilities. The official documentation provides details on how to develop and contribute plugins. Always be mindful of the source and trustworthiness of any third-party plugins you install.

Dependency Groups
Poetry supports defining multiple dependency groups beyond the default dependencies and dev (or test). This is particularly useful for managing different sets of tools for various development phases or environments.
Example pyproject.toml with custom groups:
[tool.poetry.dependencies]
python = "^3.9"
requests = "^2.28.1"
[tool.poetry.group.dev.dependencies]
pytest = "^7.1.2"
black = "^22.6.0"
[tool.poetry.group.docs.dependencies]
sphinx = "^5.0.2"
myst-parser = "^0.18.0"
You can then install dependencies for a specific group:
poetry install --with docs
poetry install --all-groups
By following these steps, you can successfully install and configure Poetry, enabling you to manage your Python projects with greater efficiency and reliability. Poetry’s integrated approach to dependency management, virtual environments, and packaging makes it an indispensable tool for modern Python development.
