Error installing bcrypt with pip on OS X: can't find ffi.h (libffi is installed)
Asked Answered
L

4

38

I'm getting this error when trying to install bcrypt with pip. I have libffi installed in a couple places (the Xcode OS X SDK, and from homebrew), but I don't know how to tell pip to look for it. Any suggestions?

Downloading/unpacking bcrypt==1.0.2 (from -r requirements.txt (line 41))
  Running setup.py egg_info for package bcrypt
    OS/X: confusion between 'cc' versus 'gcc' (see issue 123)
    will not use '__thread' in the C code
    c/_cffi_backend.c:14:10: fatal error: 'ffi.h' file not found
    #include <ffi.h>
             ^
    1 error generated.
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
      File "/Users/cody/virtualenvs/analytics/build/bcrypt/setup.py", line 104, in <module>
        "Programming Language :: Python :: 3.3",
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 112, in setup
        _setup_distribution = dist = klass(attrs)
      File "build/bdist.macosx-10.9-intel/egg/setuptools/dist.py", line 239, in __init__
      File "build/bdist.macosx-10.9-intel/egg/setuptools/dist.py", line 264, in fetch_build_eggs
      File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 620, in resolve
        dist = best[req.key] = env.best_match(req, ws, installer)
      File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 858, in best_match
        return self.obtain(req, installer) # try and download/install
      File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 870, in obtain
        return installer(requirement)
      File "build/bdist.macosx-10.9-intel/egg/setuptools/dist.py", line 314, in fetch_build_egg
      File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 593, in easy_install

      File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 623, in install_item

      File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 811, in install_eggs

      File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 1017, in build_and_install

      File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 1005, in run_setup

    distutils.errors.DistutilsError: Setup script exited with error: command 'cc' failed with exit status 1
    Complete output from command python setup.py egg_info:
    OS/X: confusion between 'cc' versus 'gcc' (see issue 123)

will not use '__thread' in the C code

c/_cffi_backend.c:14:10: fatal error: 'ffi.h' file not found

#include <ffi.h>

         ^

1 error generated.

Traceback (most recent call last):

  File "<string>", line 16, in <module>

  File "/Users/cody/virtualenvs/analytics/build/bcrypt/setup.py", line 104, in <module>

    "Programming Language :: Python :: 3.3",

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 112, in setup

    _setup_distribution = dist = klass(attrs)

  File "build/bdist.macosx-10.9-intel/egg/setuptools/dist.py", line 239, in __init__

  File "build/bdist.macosx-10.9-intel/egg/setuptools/dist.py", line 264, in fetch_build_eggs

  File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 620, in resolve

    dist = best[req.key] = env.best_match(req, ws, installer)

  File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 858, in best_match

    return self.obtain(req, installer) # try and download/install

  File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 870, in obtain

    return installer(requirement)

  File "build/bdist.macosx-10.9-intel/egg/setuptools/dist.py", line 314, in fetch_build_egg

  File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 593, in easy_install



  File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 623, in install_item



  File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 811, in install_eggs



  File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 1017, in build_and_install



  File "build/bdist.macosx-10.9-intel/egg/setuptools/command/easy_install.py", line 1005, in run_setup



distutils.errors.DistutilsError: Setup script exited with error: command 'cc' failed with exit status 1

----------------------------------------
Command python setup.py egg_info failed with error code 1 in /Users/cody/virtualenvs/analytics/build/bcrypt
Laze answered 5/4, 2014 at 0:51 Comment(0)
P
84

Without using sudo and CFLAGS and CPPFLAGS (unnecessary for pip):

$ brew install pkg-config libffi
$ export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/
$ pip install bcrypt
Purchase answered 15/9, 2014 at 18:44 Comment(7)
You one smooth sailor!Haik
I used this advice to get sudo pip install cryptography to work on osx. Thanks!Throve
Worked without setting the PKG_CONFIG_PATHRecti
I believe that with the release of bcrypt 2.0.0, setting the environment variable is no longer required.Purchase
This helped me install Quartz pip install pyobjc-framework-Quartz. Thanks.Velda
The version of pkgconfig installed differs now - for me it was 3.2.1 at the time of writingZambrano
Thanks. This also works for other stuff, it helped me install pygobject and pycairo.Tremblay
L
20

I finally got it working with the following with a little help from these posts:

brew install pkg-config libffi
sudo bash
export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments
export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/
pip install bcrypt
Laze answered 17/4, 2014 at 19:51 Comment(2)
This answer is ok, but the CFLAGS and CPPFLAGS are unused so setting them is unnecessary. Also, don't use sudo to install a pip package. See my answer below.Purchase
I suspect this is because of fixes in newer versions of the pip package that make those flags unnecessary. Simply following the steps in your answer gave me build failures at the time I wrote the answer, but now they don't. I'll mark yours as accepted.Laze
F
15

Xcode was already installed for me (as mentioned in the question itself that it does provide the ffi.h header), but for some reason that didn't populate /usr/include (as Zachary Young mentioned). I dug around to see why the /usr/include wasn't populated and found that the following command fixed it:

$ xcode-select --install

Missing /usr/include after Yosemite and Xcode install?

Fitzgerald answered 26/5, 2015 at 8:30 Comment(1)
Thank you for finding that, I feels that's much better than manually linking.Nakesha
N
3

Update 26/Aug/15

I think TA's answer is better in that it's handled by the system.


First off, I'm loathe to install Brew or Ports, but that's another issue.

I've been trying to pip install cryptography, which depends on cffi, which imports ffi.h.

I am curious why no one addressed that he (and me, and I believe others) have ffi installed with Xcode:

locate ffi.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/ffi/ffi.h

since the error is specifically about "not finding" ffi.h with the following build command:

c/_cffi_backend.c:14:10: fatal error: 'ffi.h' file not found
#include <ffi.h>
...
...
/usr/bin/clang ...{omitted}... I/usr/include/ffi -I/usr/include/libffi

I have ffi.h, it's just that the system thinks it should be in /usr/include/....

My /usr/include directory happens to be empty, and not linked to anything, so I just linked the directory/file in question, to the place where it's not being found:

ln -fs {THAT_XCODE_SDK_FFI_PATH_FROM_ABOVE} /usr/include/ffi

I can now install and build cffi and cryptography.

I'm very novice when it comes to understanding build-chain/linking dynamics, and if this is bad, I don't get it... so, please let me know.

Nakesha answered 17/3, 2015 at 20:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.