Andre Borie

Fontconfig library issue with Python 3.9 on Apple Silicon

If you're working on older Python projects that may use certain PDF libraries, you may have encountered this exception before:

OSError: ctypes.util.find_library() did not manage to locate a library called 'fontconfig'

The root cause is that the Python package is still looking in the usual x86-centric paths to find the library; this breaks on Apple Silicon because there, Homebrew installs everything in /opt. Newer versions of the package fix this, but in the meantime you can easily make the existing package work with a few symlinks:

sudo mkdir -p /usr/local/lib
sudo ln -s /opt/homebrew/lib/libfontconfig.1.dylib /usr/local/lib/libfontconfig.1.dylib
sudo ln -s /opt/homebrew/lib/libfontconfig.a /usr/local/lib/libfontconfig.a
sudo ln -s /opt/homebrew/lib/libfontconfig.dylib /usr/local/lib/libfontconfig.dylib

Still no success? Try:

sudo mkdir -p /usr/local/lib
sudo cp $(brew --prefix fontconfig)/lib/libfontconfig.* /usr/local/lib

#tech