MacOS: Package 'libffi', required by 'gobject-2.0', not found

Error

When you try to install Pygobject using pip, you get the following error:

Package 'libffi', required by 'gobject-2.0', not found

Solution

First check that you have installed libffi using brew:

brew search libffi

If you have installed libffi, you will get the following output:

libffi ✔
brew search libffi  4.29s user 1.43s system 68% cpu 8.358 total

You will need to set some environment variables to make it available for compilers or pkg-config :

For compilers to find libffi you may need to set:

  export LDFLAGS="-L/usr/local/opt/libffi/lib"

For pkg-config to find libffi you may need to set:

  export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"