Poetry


Created: 14 Dec 2022, 03:27 PM | Modified: =dateformat(this.file.mtime,"dd MMM yyyy, hh:mm a") Tags: knowledge, tools


Setup on Aftershock

mamba activate base
curl -sSL https://install.python-poetry.org | python3 -
poetry completions bash >> ~/.bash_completion

since using a pre-exisiting file directory structure:

cd <workspace path>
poetry init
poetry add scikit-learn

Faced this error!

(base) darius@heat_AI_bigdata_3090_aftershock:~/Workspaces/DiSparse-Multitask-Model-Compression$ poetry add scikit-learn
Creating virtualenv disparse-mtl-pruning-6DaeE3Lt-py3.10 in /home/darius/.cache/pypoetry/virtualenvs

Failed to unlock the collection!

Seems related to python - Poetry: Failed to unlock the collection - Stack Overflow and Keyring errors during non-publishing operations · Issue #1917 · python-poetry/poetry · GitHub

Trying to resolve using gnome-keyring as per https://stackoverflow.com/a/76049791:

  • add to bashrc
  • restart shell
  • call unlock-keyring from newly restarted shell
  • run poetry add scikit-learn again

changing venv location to be within project:

poetry config virtualenvs.in-project true

If you already have created your project, you need to re-create the virtualenv to make it appear in the correct place:

poetry env list  # shows the name of the current environment
poetry env remove <current environment>
poetry install  # will create a new environment using your updated configuration

Articles

https://blogs.sap.com/2022/05/08/why-you-should-use-poetry-instead-of-pip-or-conda-for-python-projects/

https://ahmed-nafies.medium.com/pip-pipenv-poetry-or-conda-7d2398adbac9

https://betterprogramming.pub/5-reasons-why-poetry-beats-pip-python-setup-6f6bd3488a04

https://pythonspeed.com/articles/pipenv-docker/