7

I'm using a homebrew installation of python and getting an error using pip within a virtualenvwrapper environment:

No package 'libffi' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable

Homebrew has a formula for libffi (brew install libffi), which seemed to be successful.

I can run

$ python-config --include

which yields:

-I/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/include/python2.7

So should I "add the directory containing `libffi.pc'"?

echo $PKG_CONFIG_PATH yields an empty string.

[Someone on SO had recommended][3]:

Use -I /opt/local/include on the command line 

or

C_INCLUDE_PATH=/opt/local/include in the environment.

Would I add the line:

C_INCLUDE_PATH=/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/include/python2.7

to the ~/.bash_profile?

or possibly export PKG_CONFIG_PATH=/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/include/python2.7

12

Figured it out.

brew install libffi

locate libffi.pc

(in this case i also had to run the command to build the locate database, for which the code was included in the prompt from locate)

returned /usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/libffi.pc

Then within the virtualenv ran export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/ (the path to libffi.pc).

Confirmed with echo $PKG_CONFIG_PATH, which showed the path.

And pip "Successfully installed" the modules!

In case it's useful, this is how I got the virtualenvwrapper environment working:

I have added the following contents to the ~/.bash_profile as well as ~/.bashrc files:

export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
export PATH=/usr/local/bin:$PATH

As per this tutorial.

  • 2
    For a more generic way I use: export PKG_CONFIG_PATH="$(brew --prefix libffi)/lib/pkgconfig/" – David Boho Apr 9 '19 at 5:16
  • @DavidBoho underrated comment! Only this worked for me. – Gio Aug 2 '19 at 9:22
3

FWIW, I had to actually use export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/ to get this to work. Same command, but just the directory instead of the libffi.pc file itself.

1

On my case I got the next error message when running npm i :

node-gyp rebuild

Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libffi', required by 'gobject-2.0', not found
gyp: Call to 'pkg-config --cflags  cairo poppler-qt5' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
I figured out the problem was on exporting the PATH

So I ran brew reinstall -s poppler

At the end of the installation you can run the export of the paths

If you need to have qt first in your PATH run:
  echo 'export PATH="/usr/local/opt/qt/bin:$PATH"' >> ~/.zshrc

For compilers to find qt you may need to set:
  export LDFLAGS="-L/usr/local/opt/qt/lib"
  export CPPFLAGS="-I/usr/local/opt/qt/include"

For pkg-config to find qt you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/qt/lib/pkgconfig"

This fixed it for me.

I hope you find it helpfull.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .