'How to rebuild Poetry environment from scratch and force reinstall everything?

Poetry has some stale dependencies because the use of develop = true packages. Poetry cannot figure out on its own that dependencies have been updated. How do I force Poetry to reinstall everything in its virtualenv to work around this issue?



Solution 1:[1]

These instructions are only for Linux/macOS for Windows Subsystem for Linux. For the Microsoft Windows shell, please use your own command-line knowledge to apply these instructions.

Recreating Poetry environment

Do the following in the folder with pyproject.toml:

# Stop the current virtualenv if active or alternative use
# `exit` to exit from a Poetry shell session
deactivate

# Remove all the files of the current environment of the folder we are in
rm -rf `poetry env info -p` 

# Reactivate Poetry shell
poetry shell

# Install everything
poetry install

Recreating Poetry environment with different Python version

Poetry may refer to your installed Python version, so you might tell it to change its link to your python interpreter as well:

# Make Poetry to use python 3.9 from Homebrew, installed earlier
poetry env use `which python3.9`
poetry shell
python -V
Python 3.9.9

Kudos to this tip about removing the virtualenv.

Fixing damaged poetry command

If the poetry command itself is damaged and no longer runs, you can reinstall Poetry by:

which poetry
/Users/mikkoohtamaa/.poetry/bin/poetry

Then remove this and install:

rm -rf /Users/mikkoohtamaa/.poetry

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3 -

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1