Managing Python Projects with Poetry (and a Bit of pyenv)
If you're tired of juggling virtual environments, editing requirements.txt
by hand, or worrying about dependency conflicts, Poetry offers a modern, all-in-one solution for Python project management. It handles dependency resolution, virtual environments, and packaging, all through a single CLI interface. Unlike traditional workflows where you use venv
or virtualenv
alongside separate tools for dependency management and publishing, Poetry is purpose-built to manage the full lifecycle of a Python project—cleanly and reproducibly.
Getting Started with Poetry
To install Poetry, run the official installation script:
curl -sSL https://install.python-poetry.org | python3 -
Once installed, confirm that it's available with:
poetry --version
Poetry uses the pyproject.toml
format, a modern standard for Python project configuration. You can create a new project scaffold with:
poetry new myproject
This generates a minimal but complete structure including tests, a package folder, and the necessary metadata. For an existing project, simply run poetry init
and follow the prompt to define dependencies.
Managing Dependencies and Virtual Environments
Poetry automatically manages a virtual environment for each project. When you run poetry install
, it creates an isolated environment, resolves and installs dependencies based on your pyproject.toml
, and locks them with exact versions in poetry.lock
. You never need to touch pip
or venv
directly.
To install packages, use:
poetry add requests
Dev-only dependencies like linters or test frameworks can be added with:
poetry add --dev pytest black
You can run scripts or Python files inside the managed environment with:
poetry run python script.py
Or open an interactive shell inside the environment:
poetry shell
This workflow ensures isolation, reproducibility, and avoids cluttering your global Python installation.