Python cannot use brew-installed libraries on Apple Silicon #3424
Replies: 2 comments 5 replies
-
Which python are you using? OS python? Arm homebrew python? X64 homebrew python? Python installed from a pkg? How can we reproduce the issue? |
Beta Was this translation helpful? Give feedback.
-
Note that Apple considers
Setting
This means that setting If you must rely on |
Beta Was this translation helpful? Give feedback.
-
Hello team,
I recently got my hands on a M2 Macbook Pro.
I reinstalled brew, and figured out (should have read the instructions before) that /opt/homebrew is the new home on arm64.
I understand that decision, and in a lot of ways, it's a good thing. It makes it clearer what is x64 stuff (migrated from an intel Mac) vs arm64.
However, I found myself in a bit of a pickle.
One of the python packages I'm using is
WeasyPrint
, and it relies on libffi, fontconfig, pango and a couple of other things.I installed these using brew, but I was still having the following error:
I tried setting
LD_LIBRARY_PATH=/opt/homebrew/lib
, to no avail.According to the python documentation for ctypes, on MacOS, the
ctypes.util.find_library
function looks at a predetermined set of paths to resolve dynamic libraries, and does not useLD_LIBRARY_PATH
.I resorted to create a symlink to
/opt/homebrew/Cellar
in/usr/local
, and that was enough to solve things.The links from my x64 brew install were still in
/usr/local/lib
, and those point to the Cellar, so the link above restored things.So in a nutshell, the issue is:
/opt/homebrew
on arm64/usr/lib
or/usr/local/lib
(maybe others, I couldn't find an exact list)/usr/local
on Mac arm64 platformsNot sure what the best solution would be at this point, but symbolic links do the trick, and are quite easy to setup.
Problem is that they interfere with a potential previous x64 installation that would need to be removed beforehand.
edit
After looking at the code for ctypes in Python 3.9, I found that the
DYLD_LIBRARY_PATH
environment variable is actually taken into account as well when resolving libraries.Setting
DYLD_LIBRARY_PATH=/opt/homebrew/lib
in my .zshenv solved the issue, so that's what I'm going to stick with.The solution might just be good documentation on that topic.
Beta Was this translation helpful? Give feedback.
All reactions