Introduction
Introduction #
Poetry is a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
System requirements #
Poetry requires Python 3.7+. It is multi-platform and the goal is to make it work equally well on Linux, macOS and Windows.
Installation #
Poetry provides a custom installer that will install poetry isolated
from the rest of your system.
-
Install Poetry
Install Poetry by downloading and executing the installation script.
Linux, macOS, Windows (WSL)
curl -sSL https://install.python-poetry.org | python3 -Windows (Powershell)
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -NoteIf you have installed Python through the Microsoft Store, replacepywithpythonin the command above.NoteNote that the installer does not support Python < 3.7.WarningThe previousget-poetry.pyinstaller is now deprecated, if you are currently using it you should migrate to the new, supported,install-poetry.pyinstaller. -
Add Poetry to your PATH
The installer installs the
poetrytool to Poetry’sbindirectory. This location depends on your system:$HOME/.local/binfor Unix%APPDATA%\Python\Scriptson Windows
If this directory is not on your
PATH, you will need to add it manually if you want to invoke Poetry with simplypoetry.Alternatively, you can use the full path to
poetryto use it. -
Check the installation
Once Poetry is installed you can execute the following:
poetry --versionIf you see something like
Poetry (version 1.2.0)then you are ready to use Poetry. -
Configure the installation
By default, Poetry is installed into the user’s platform-specific home directory. If you wish to change this, you may define the
POETRY_HOMEenvironment variable:curl -sSL https://install.python-poetry.org | POETRY_HOME=/etc/poetry python3 -If you want to install prerelease versions, you can do so by passing
--previewoption toinstall-poetry.pyor by using thePOETRY_PREVIEWenvironment variable:curl -sSL https://install.python-poetry.org | python3 - --preview curl -sSL https://install.python-poetry.org | POETRY_PREVIEW=1 python3 -Similarly, if you want to install a specific version, you can use
--versionoption or thePOETRY_VERSIONenvironment variable:curl -sSL https://install.python-poetry.org | python3 - --version 1.2.0 curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.2.0 python3 -You can also install Poetry from a
gitrepository by using the--gitoption:curl -sSL https://install.python-poetry.org | python3 - --git https://github.com/python-poetry/poetry.git@master -
Update Poetry
If you want to install pre-release versions, you can use the
--previewoption.poetry self update --previewAnd finally, if you want to install a specific version, you can pass it as an argument to
self update.poetry self update 1.2.0WarningPoetry versions installed using the now deprecatedget-poetry.pyinstaller will not be able to use this command to update to 1.2 releases or later. Migrate to using theinstall-poetry.pyinstaller orpipx. -
Uninstall Poetry
If you decide Poetry isn’t your thing, you can completely remove it from your system by running the installer again with the
--uninstalloption or by setting thePOETRY_UNINSTALLenvironment variable before executing the installer.curl -sSL https://install.python-poetry.org | python3 - --uninstall curl -sSL https://install.python-poetry.org | POETRY_UNINSTALL=1 python3 -
Enable tab completion for Bash, Fish, or Zsh #
poetry supports generating completion scripts for Bash, Fish, and Zsh.
See poetry help completions for full details, but the gist is as simple as using one of the following:
# Bash
poetry completions bash > /etc/bash_completion.d/poetry
# Fish
poetry completions fish > ~/.config/fish/completions/poetry.fish
# Zsh
poetry completions zsh > ~/.zfunc/_poetry
# Oh-My-Zsh
mkdir $ZSH_CUSTOM/plugins/poetry
poetry completions zsh > $ZSH_CUSTOM/plugins/poetry/_poetry
# prezto
poetry completions zsh > ~/.zprezto/modules/completion/external/src/_poetry
For zsh, you must then add the following line in your ~/.zshrc before compinit:
fpath+=~/.zfunc
For oh-my-zsh, you must then enable poetry in your ~/.zshrc plugins
plugins(
poetry
...
)