poetry returns 'dyld: Library not loaded ... image not found' following brew install while inside virtual environment
Asked Answered
M

6

35

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/[email protected]/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
Metaphysic answered 31/1, 2022 at 1:16 Comment(0)
B
59

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 -
Berri answered 8/9, 2022 at 20:59 Comment(3)
does not work in my caseBowser
@Bowser Please add some context as to why it didn't work for you.Berri
This also did not work for me. The error: Library not loaded: @loader_path/../Python and then zsh: no such file or directory: /use/lib/PythonGourmandise
A
19

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 -

Actin answered 2/7, 2023 at 19:32 Comment(3)
This solved my problem, now the poetry referring the python version set by pyenv instead of system default. thanksGlossematics
@sairam What a genius !! saved my day buddy, This has to be an accepted answerKriskrischer
This answer works for me. I also uninstalled the brew version.Carranza
M
16

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!

Metaphysic answered 31/1, 2022 at 20:57 Comment(4)
You magnificent beauty.Tyeshatyg
@Metaphysic 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.Berri
Just to add to this, for me it was enough to just update poetry with poetry self updateAuthenticate
totally solved it. I think i ran brew update/upgrade (whichever does the installed apps updates) inside a poetry shell. Lesson learned!! Thank you!!Faro
U
15

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
Unrestrained answered 30/8, 2023 at 18:55 Comment(3)
I have Python 3.11 installed with home brew and this was the only solution that worked for meSorrell
I tried all the other answers, but this one worked immediately. Thank you! This needs to be in the poetry docs. I would have done this first.Lona
Worked like charm.Fluidize
D
13

At the time of writing, there is an open issue in the poetry repo for installations failing on macos: https://github.com/python-poetry/install.python-poetry.org/issues/24

There is a workaround posted in this comment:

curl -sSL https://install.python-poetry.org | sed 's/symlinks=False/symlinks=True/' | python3 -
Detraction answered 17/9, 2023 at 0:12 Comment(0)
G
0

Following the recent update to brew 4.3.0, a brew autoremove was triggered for the first time on my machine to remove dangling dependencies.

This has led to a similar error when trying to operate poetry:

dyld: Library not loaded: '/opt/homebrew/opt/gettext/lib/libintl.8.dylib'
Referenced from: '/Users/me/.pyenv/versions/3.11.4/bin/python3.11'

Indeed gettext was one of the dangling dependencies that were auto-removed.

So there are two possible solutions here:

  1. Workaround: reinstating gettext even though it's no longer a required dependency:
brew install gettext
  1. Fix: reinstalling pyenv's affected python, from which poetry's virtual environment derives:
pyenv uninstall 3.11.4
pyenv install 3.11.4
Gintz answered 15/5, 2024 at 13:0 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.