If you happen to run into issues whereby a home-brew installed pypy can’t find the homebrew libraries, this is because by default brew modifies python installations to search homebrew. But it doesn’t do it for pypy3.

If you look at the formulae for python3.10 here you will see:

    inreplace "./Lib/ctypes/macholib/dyld.py" do |f|
      f.gsub! "DEFAULT_LIBRARY_FALLBACK = [",
              "DEFAULT_LIBRARY_FALLBACK = [ '#{HOMEBREW_PREFIX}/lib', '#{Formula["openssl@1.1"].opt_lib}',"
      f.gsub! "DEFAULT_FRAMEWORK_FALLBACK = [", "DEFAULT_FRAMEWORK_FALLBACK = [ '#{HOMEBREW_PREFIX}/Frameworks',"
    end

This is not in the brew formulae for pypy3 (which is likely a bug). You can find the location of the file which needs patching like so

> pypy3
...
>>>> import ctypes.util
>>>> print(os.path.dirname(ctypes.util.__file__) + "/macholib/dyld.py")
/opt/homebrew/Cellar/pypy3.10/7.3.15/libexec/lib/pypy3.10/ctypes/macholib/dyld.py

Edit that file and perform the relevant substitutions, eg:

DEFAULT_FRAMEWORK_FALLBACK = [ '/opt/homebrew/Frameworks',
    os.path.expanduser("~/Library/Frameworks"),
    "/Library/Frameworks",
    "/Network/Library/Frameworks",
    "/System/Library/Frameworks",
]

DEFAULT_LIBRARY_FALLBACK = ['/opt/homebrew/lib', '/opt/homebrew/opt/openssl@3/lib',
    os.path.expanduser("~/lib"),
    "/usr/local/lib",
    "/lib",
    "/usr/lib",
]

Leave a Reply

Your email address will not be published. Required fields are marked *