24

I ran brew install postgresql while inside a poetry environment. Since then, I can't interact with poetry.

λ ~/ poetry
dyld: Library not loaded: /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/Python
  Referenced from: /Users/<my username>/Library/Application Support/pypoetry/venv/bin/python
  Reason: image not found
[1]    5634 abort      poetry

I get the same output when I try poetry <any other command>. I tried removing my virtual environments from λ ~/Library/Caches/pypoetry/virtualenvs/ expecting to be able to reinstall them from the .toml files in my projects, but can't run poetry install because I receive the same error.

I am running MacOS 10.15.7, Homebrew 3.3.12, poetry 1.1.12, & pyenv 2.2.4.

ECHO $PATH
/Users/<my username>/.poetry/bin:~/.local/bin:/Users/<my username>/Library/Python/3.9/bin:/shims:/Users/<my username>/.datacoral/cli/bin:/Users/<my username>/.nvm/versions/node/v12.13.0/bin:/Users/<my username>/bin:/usr/local/bin:/Users/<my username>/.pyenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/<my username>/.local/bin:/Users/<my username>/.local/bin
eve-hunt
  • 381
  • 2
  • 6

4 Answers4

41

I faced this issue because when I executed brew install, brew updated the patch version of Python from 3.9.13_1 to 3.9.14.

This can be easily resolved by running the following to uninstall and then install poetry.

curl -sSL https://install.python-poetry.org | python3 - --uninstall
curl -sSL https://install.python-poetry.org | python3 -
PrivateOmega
  • 2,509
  • 1
  • 17
  • 27
14

I'm resolving this in case someone runs into the same issue.

Uninstalling and reinstalling poetry fixed the problem. I wasn't able to do this with the --uninstall option and instead had to do it manually. I first ran rm -rf pypoetry inside ~/Library/Application Support/. Then I re-ran the install line from poetry's site: curl -sSL https://install.python-poetry.org | python3 -.

The cause of the issue was using poetry shell instead of just poetry run jupyterlab –– this opened me up to absent-mindedly screwing up the poetry install by running brew installs while in the shell. Lesson learned!

eve-hunt
  • 381
  • 2
  • 6
  • You magnificent beauty. – cs_stackX Apr 29 '22 at 13:22
  • 1
    @eve-hunt Are you sure its caused by running brew install in poetry shell? My feeling is there are chances normal brew installs updates python in brew, say like a patch version and poetry would be pointing to old version's location. – PrivateOmega Sep 08 '22 at 20:52
  • Just to add to this, for me it was enough to just update poetry with `poetry self update` – StFS Dec 22 '22 at 13:09
  • totally solved it. I think i ran brew update/upgrade (whichever does the installed apps updates) inside a poetry shell. Lesson learned!! Thank you!! – atomscale Jul 14 '23 at 20:47
8

This is because brew might have installed using a different python version.

To fix this, we need to uninstall poetry, if you are using pyenv, change to required python version and then re-install poetry. Now poetry should be installed with the required python version.

# Uninstall poetry
curl -sSL https://install.python-poetry.org | python3 - --uninstall

# change to required python
pyenv local 3.10.8

# activate python
eval "$(pyenv init --path)"

# check python version
python --version

# Install latest poetry
curl -sSL https://install.python-poetry.org | python3 -

Sairam Krish
  • 10,158
  • 3
  • 55
  • 67
1

I tried all the above solutions, even searched for possible poetry entries in different places of the system, all deleted and uninstalled. Nothing worked, and as I have Python (3.8, 3.9, 3.10 and 3.11) installed on macOS with homebrew, the only solution was to install poetry via homebrew too.

brew install poetry
nuin
  • 607
  • 1
  • 6
  • 11