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?

- 82,057
- 50
- 264
- 435
2 Answers
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
To reinstall the packages for the Poetry environment in the current working directory (UNIX shell):
# Enter the current Poetry environment
poetry shell
# Remove the current environment
# as referred by path to Python interpreter
poetry env remove $(which python)
# Reinstall from Poetry's cache
poetry install
Recreating Poetry environment manually
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
POETRY_LOCATION=`poetry env info -p`
echo "Poetry is $POETRY_LOCATION"
rm -rf "$POETRY_LOCATION"
# 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:
# macOS
rm -rf /Users/mikkoohtamaa/.poetry
rm -rf "/Users/$USER/Library/Application Support/pypoetry/venv"
# Linux
rm -rf ~/.local/share/pypoetry/
# Download and run Poetry install script
# If your curl is messed up you can try with --insecure flag
curl -sSL https://install.python-poetry.org/ | python3 - --force
Extreme painful issues
Sometimes Poetry may just fail to install after you have upgraded your Python e.g. with Homebrew. This might be to do with a fact who Poetry determines which Python version to use.
Errors you can see may include:
cat /Users/moo/poetry-installer-error-t0zfi7kb.log
dyld[6526]: Library not loaded: @loader_path/../Python
Referenced from: <7295E559-55D4-3ACA-9820-D95D1F4AE151> /Users/moo/Library/Application Support/pypoetry/venv/bin/python3.10
Reason: tried: '/Users/moo/Library/Application Support/pypoetry/venv/bin/../Python' (no such file), '/System/Volumes/Preboot/Cryptexes/OS@loader_path/../Python' (no such file), '/Users/moo/Library/Application Support/pypoetry/venv/bin/../Python' (no such file), '/usr/local/lib/Python' (no such file), '/usr/lib/Python' (no such file, not in dyld cache)
Traceback:
File "<stdin>", line 923, in main
File "<stdin>", line 562, in run
In this case, recommended approach is to switch away from Homebrew based Pythons and start using pyenv:
brew install pyenv
# Follow the instructions
pyenv init
Then in a new shell install a specific Python version and check it is being used:
pyenv install 3.10
pyenv global 3.10
which python
Points to pyenv:
/Users/moo/.pyenv/shims/python
Now reinstall Poetry using a specific Python version and it should work:
curl -sSL https://install.python-poetry.org/ | python3.10 -

- 82,057
- 50
- 264
- 435
-
2The "rm -rf `poetry env info -p` " command will break poetry. Once executed all poetry commands fail with "No pyvenv.cfg file". – fret Feb 13 '22 at 22:12
-
You probably had misinstalled poetry. You can check with `which poetry` command what poetry binary it tries to use. – Mikko Ohtamaa Feb 14 '22 at 14:52
-
1`poetry env info -p` yielded nothing for me (it doesn't work outside the activated env), so i used `poetry env list --full-path` and manually copied the path. Thus I recommend splitting `rm -rf \`
\`` into 2 steps, or a workaround could be `rm -rf \`poetry run poetry env info -p\`` – smido Mar 21 '22 at 11:55 -
2Indeed, passing the output of a command to `rm -rf` sounds like a bad advise. – Kristoffer Bakkejord Jul 08 '22 at 08:46
-
Beware that when using pyenv poetry env info -p is showing a shim, so that this instruction can broke poetry at all if poetry was installed using this shim. Now I have: "Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding" when running any poetry command – Mesco May 30 '23 at 11:52
-
I believe the command to obtain the path to the environment is now: poetry env info --path – cast42 Jun 15 '23 at 09:57
The official documentation recommends the poetry env remove
command, which accepts any of the following syntax:
poetry env remove /full/path/to/python
poetry env remove python3.11
poetry env remove 3.11
poetry env remove test-O3eWbxRl-py3.11
You can remove all virtual environments at once with poetry env remove --all
As with the accepted answer this will need to be followed by poetry shell
and poetry install
to recreate the environment and reinstall dependencies respectively.

- 513
- 5
- 10