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. Poetry offers a lockfile to ensure repeatable installs, and can build your project for distribution.
System requirements #
Poetry requires Python 3.8+. It is multi-platform and the goal is to make it work equally well on Linux, macOS and Windows.
Installation #
We provide a custom installer that will install Poetry in a new virtual environment to isolate it from the rest of your system. This ensures that dependencies will not be accidentally upgraded or uninstalled, and allows Poetry to manage its own environment.
-
Install Poetry
The installer script is available directly at install.python-poetry.org, and is developed in its own repository. The script can be executed directly (i.e. ‘curl python’) or downloaded and then executed from disk (e.g. in a CI environment).
WarningTheinstall-poetry.pyinstaller has been deprecated and removed from the Poetry repository. Please migrate from the in-tree version to the standalone version described above.Linux, macOS, Windows (WSL)
curl -sSL https://install.python-poetry.org | python3 -NoteNote: On some systems,pythonmay still refer to Python 2 instead of Python 3. We always suggest thepython3binary to avoid ambiguity.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. -
Install Poetry (advanced)
By default, Poetry is installed into a platform and user-specific directory:
~/Library/Application Support/pypoetryon MacOS.~/.local/share/pypoetryon Linux/Unix.%APPDATA%\pypoetryon Windows.
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 the
--previewoption to the installation script or by using the$POETRY_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 the$POETRY_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 -
Add Poetry to your PATH
The installer creates a
poetrywrapper in a well-known, platform-specific directory:$HOME/.local/binon Unix.%APPDATA%\Python\Scriptson Windows.$POETRY_HOME/binif$POETRY_HOMEis set.
If this directory is not present in your
$PATH, you can add it in order to invoke Poetry aspoetry.Alternatively, the full path to the
poetrybinary can always be used:~/Library/Application Support/pypoetry/venv/bin/poetryon MacOS.~/.local/share/pypoetry/venv/bin/poetryon Linux/Unix.%APPDATA%\pypoetry\venv\Scripts\poetryon Windows.$POETRY_HOME/venv/bin/poetryif$POETRY_HOMEis set.
-
Use Poetry
Once Poetry is installed and in your
$PATH, you can execute the following:poetry --versionIf you see something like
Poetry (version 1.2.0), your install is ready to use! -
Update Poetry
Poetry is able to update itself when installed using the official installer.
poetry self updateIf 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.0WarningPoetry1.1series releases are not able to update in-place to1.2or newer series releases. To migrate to newer releases, uninstall using your original install method, and then reinstall using the methods above. -
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 -WarningIf you installed using the deprecated
get-poetry.pyscript, you should remove the path it uses manually, e.g.rm -rf "${POETRY_HOME:-~/.poetry}"Also remove ~/.poetry/bin from your
$PATHin your shell configuration, if it is present.
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 #
Auto-loaded (recommended) #
poetry completions bash >> ~/.bash_completion
Lazy-loaded #
poetry completions bash > ${XDG_DATA_HOME:-~/.local/share}/bash-completion/completions/poetry
Fish #
poetry completions fish > ~/.config/fish/completions/poetry.fish
Zsh #
poetry completions zsh > ~/.zfunc/_poetry
You must then add the following lines in your ~/.zshrc, if they do not already exist:
fpath+=~/.zfunc
autoload -Uz compinit && compinit
Oh My Zsh #
mkdir $ZSH_CUSTOM/plugins/poetry
poetry completions zsh > $ZSH_CUSTOM/plugins/poetry/_poetry
You must then add poetry to your plugins array in ~/.zshrc:
plugins(
poetry
...
)
prezto #
poetry completions zsh > ~/.zprezto/modules/completion/external/src/_poetry