Poetry⚓︎
Install Poetry⚓︎
First, install Poetry. This can be done through
To ensure Poetry is up-to-date, run
Then, navigate to the project's root directory, and create the virtualenv
environment with
- This project also supports 3.11 - 3.13 if you want to use those instead.
In future sessions (on the CLI), you can enter the environment by navigating to the project's root directory and running
Decoupling Python and Poetry installs⚓︎
When installing Poetry, it will usually bundle a Python install. But when using Homebrew, it tends to automatically update Poetry and the Python dependency. If it upgrades the minor Python version - like 3.10 -> 3.11 - it can break an existing environment.
As such, it is best practice to decouple the Python install from Poetry. pyenv is a great, simple tool to manage Python installations.
Then install a specific Python version. The executable path can be found with
which can be used as the interpreter for the Poetry environment with
Now you should have a static path to a specific Python install.
Tip
Run poetry config virtualenvs.in-project true
to store the virtualenv in the project directory. This is useful if
you want full visibility of the environment, instead of it being hidden elsewhere on your filesystem.
Install the project⚓︎
To install everything from this project's Poetry configuration, run
To only install the core dependencies, instead run
Since it will create a virtualenv
environment for you, you don't need to run it in conjunction with another
environment manager, such as conda.
- Open the project
- Click Add New Interpreter -> Add Local Interpreter... -> Poetry Environment
- Check Existing environment. The environment you just created should appear in the dropdown menu
Creating your own configuration⚓︎
To create your own Poetry configuration in pyproject.toml, run
and follow the instructions. Then to port any dependencies from requirements.txt
and requirements-dev.txt
, run
cat requirements.txt | grep -E '^[^# ]' | cut -d= -f1 | xargs -n 1 poetry add
cat requirements-dev.txt | grep -E '^[^# ]' | cut -d= -f1 | xargs -n 1 poetry add --group dev
Dependencies can be segmented into different groups. See pyproject.toml.
It is recommended to maintain dependencies with Poetry, and export them (1) to requirements.txt
and requirements-dev.txt
if needed (2), e.g.,
- Exporting dependencies may require the plugin
poetry-plugin-export
. Install it withpoetry self add poetry-plugin-export
- Check out quality#pre-commit for a pre-commit hook to do this automatically.
poetry export --without-hashes -f requirements.txt -o requirements.txt
poetry export --without-hashes --only dev -f requirements.txt -o requirements-dev.txt
This repo separates development dependencies into dev, tests, and docs groups. To export these, run