Install `Poetry` in Ubuntu
Introduction
Poetry is a tool for dependency management and packaging in Python. It offers a lockfile to ensure repeatable installs, and can build your project for distribution.
Below are the instructions for Ubuntu. Complete instructions list for other methods here: https://python-poetry.org/docs/#installing-with-the-official-installer
Install pyenv
to manage python versions. Here is the complete source
pyenv
to manage python versions. Here is the complete source-
Installing via the recommended way
curl https://pyenv.run | bash -
Setup shell environment by adding the commands to the
.bashrc
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrcecho 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrcecho 'eval "$(pyenv init -)"' >> ~/.bashrc -
Restart shell
exec "$SHELL" -
(optional) Build environment for
Python
sudo apt update; sudo apt install build-essential libssl-dev zlib1g-dev \libbz2-dev libreadline-dev libsqlite3-dev curl git \libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev -
Install a python version
pyenv install -l # gives the list of all available versionspyenv install 3.12 # install the selected version -
Set the version
pyenv global 3.12 # setting the python environment -
Uninstall python version
pyenv uninstall 3.12 # removes this version -
(optional) Update
pyenv
pyenv update -
(optional) Uninstall
pyenv
: To completely uninstall Pyenv, remove all Pyenv configuration lines from your shell startup configuration, and then remove its root directory. This will delete all Python versions that were installed under the$(pyenv root)/versions/ directory
:rm -rf $(pyenv root)
Instructions for poetry
installation
-
Download the Poetry install script and execute
curl -sSL https://install.python-poetry.org | python3 - -
Add Poetry to
Path
The installer creates a poetry wrapper in a well-known, platform-specific directory:
$HOME/.local/bin
on Unix.%APPDATA%\Python\Scripts
on Windows.$POETRY_HOME/bin
if $POETRY_HOME is set.
# TODO: check if the `poetry` is actually installed in the pathecho 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bashrc# To apply the changessource ~/.bashrc -
Use
Poetry
poetry --version -
Autocompletion
poetry completions bash >> ~/.bash_completion -
Update
Poetry
(optional)poetry self update -
Uninstall
Poetry
(optional)curl -sSL https://install.python-poetry.org | python3 - --uninstallcurl -sSL https://install.python-poetry.org | POETRY_UNINSTALL=1 python3 -
Settings for fish
shell configuration
In the config.fish
file, add the following code snippet to recognize pyenv
and poetry
# pyenv settings#------------------------# Set pyenv root directoryset -x PYENV_ROOT $HOME/.pyenv
# Add pyenv to PATHset -x PATH $PYENV_ROOT/bin $PATH
# Initialize pyenvif test -d $PYENV_ROOT status --is-interactive; and source (pyenv init --path | psub) source (pyenv init - | psub)end
# poetry settings#------------------------# Add Poetry to PATHset -x PATH $HOME/.local/bin $PATH