Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Build a Social Network with Flask Making Strong Users Cryptographic Hashing with Flask-Bcrypt

I'm trying to install flask-bcrypt on Mac but getting "error: command '/usr/bin/clang' failed with exit status 1"

I'm trying to install flask-bcrypt on my MacBook Pro (Retina, 15-inch, Mid 2014) running El Capitan (v10.11.1) via the following:

pip3 install flask-bcrypt

And it is producing the following error:

c/_cffi_backend.c:13:10: fatal error: 'ffi.h' file not found
    #include <ffi.h>
             ^
    1 error generated.
    Note: will not use '__thread' in the C code
    The above error message can be safely ignored
    error: command '/usr/bin/clang' failed with exit status 1

Any ideas?

4 Answers

To fix this error I found some help here: [http://stackoverflow.com/questions/22875270/error-installing-bcrypt-with-pip-on-os-x-cant-find-ffi-h-libffi-is-installed] Homebrew is needed to run the recommended scripts: [http://brew.sh/]

After that I ran easy_install flask-bcrypt while in my virtualenv and it has seemed to install! I'm sure pip install flask-bcrypt would work at that point too.

I am pretty sure it worked for me too..

bash /* Installed HomeBrew */ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

/* brew install pig-config libffi */ brew install pig-config libffi

/* activate vent */ source ./venv3.5/bin/activate

/* add pkg_config_path*/ export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/

_configtest.c:1:1: error: thread-local storage is not supported for the current target __thread int some_threadlocal_variable_42; ^ 1 error generated.


Failed building wheel for crypt


Failed building wheel for cffi

pip install py-bcrypt

pip install Flask-bcrypt

pip install Flask-login

pip install Flask-WTF

pip install peewee

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

I've been there! The key is to install py-bcrypt (instead of plain bcrypt) then install flask-bcrypt.

See post on How to Run Flask Locally for a complete list of pip install commands.

Here is an explicit flow of getting "python app.py" to run in a virtual env.

The flow below creates a fresh virtual environment. After each install I ran "python app.py" to see what was missing (not shown), I then installed just one module at a time until it all worked. I used "pip freeze" to display the currently installed modules at each step.

If you do not wish to use a (highly recommended) virtual env, you can skip the activate step.

# Create new virtual env using python 3.4
$ virtualenv -p /usr/bin/python3.4  venv3.4

# Activate new venv
$ . ./venv3.4/bin/activate

# check what is stalled
(venv3.4)s pip freeze

# Nothing installed, start with Flask
(venv3.4)s pip install Flask
(venv3.4)s pip freeze
Flask==0.10.1
Jinja2==2.8  # <-- new
MarkupSafe==0.23  # <-- new
Werkzeug==0.10.4  # <-- new
itsdangerous==0.24  # <-- new

# Install py-bcrypt
(venv3.4)s pip install py-bcrypt
(venv3.4)s pip freeze
Flask==0.10.1
Jinja2==2.8
MarkupSafe==0.23
Werkzeug==0.10.4
itsdangerous==0.24
py-bcrypt==0.4  # <-- new

# Install Flask-bcrypt
(venv3.4)s pip install Flask-bcrypt
(venv3.4)s pip freeze
Flask==0.10.1
Flask-Bcrypt==0.7.1  # <-- new
Jinja2==2.8
MarkupSafe==0.23
Werkzeug==0.10.4
bcrypt==2.0.0  # <-- new
cffi==1.3.0  # <-- new
itsdangerous==0.24
py-bcrypt==0.4
pycparser==2.14  # <-- new
six==1.10.0  # <-- new

# Install Flask-login
(venv3.4)s pip install Flask-login
(venv3.4)s pip freeze
Flask==0.10.1
Flask-Bcrypt==0.7.1
Flask-Login==0.3.2  # <-- new
Jinja2==2.8
MarkupSafe==0.23
Werkzeug==0.10.4
bcrypt==2.0.0
cffi==1.3.0
itsdangerous==0.24
py-bcrypt==0.4
pycparser==2.14
six==1.10.0

# Install Flask-WTF
(venv3.4)s pip install Flask-WTF
(venv3.4)s pip freeze
Flask==0.10.1
Flask-Bcrypt==0.7.1
Flask-Login==0.3.2
Flask-WTF==0.12  # <-- new
Jinja2==2.8
MarkupSafe==0.23
WTForms==2.0.2  # <-- new
Werkzeug==0.10.4
bcrypt==2.0.0
cffi==1.3.0
itsdangerous==0.24
py-bcrypt==0.4
pycparser==2.14
six==1.10.0

# Install peewee
(venv3.4)s pip install peewee
(venv3.4)s pip freeze
Flask==0.10.1
Flask-Bcrypt==0.7.1
Flask-Login==0.3.2
Flask-WTF==0.12
Jinja2==2.8
MarkupSafe==0.23
WTForms==2.0.2
Werkzeug==0.10.4
bcrypt==2.0.0
cffi==1.3.0
itsdangerous==0.24
peewee==2.6.4  # <-- new
py-bcrypt==0.4
pycparser==2.14
six==1.10.0

# Glory Time!
(venv3.4)s python app.py 
 * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
 * Restarting with stat

I did just like you asked and got this error...

Failed building wheel for py-bcrypt Failed to build py-bcrypt Installing collected packages: py-bcrypt Running setup.py install for py-bcrypt Successfully installed py-bcrypt-0.4 (venv3.5)bash-3.2$ which pip /Users/dierkpol/venv3.5/bin/pip

Chris Freeman
Chris Freeman
Treehouse Moderator 68,457 Points

Which shell or command window are you running these commands in? The ". ./venv3.4/bin/activate" works with bash shell.

try source ./venv3.4/bin/activate

Chris, thank you for your response. I was having trouble getting virtualenv to work. I ended up using easy_install to get it to work properly. However, when continuing down your path, I still get hung up at pip install Flask-bcrypt. I was able to get py-bcrypt installed though.

I'm still getting the error: command '/usr/bin/clang' failed with exit status 1 error, even while in my activated virtualenv

I changed from the tcsh to bash and activate worked...

I was able to get the "venv" to start up... i used pip.. to install flask successfully...

pip install Flask Collecting Flask Using cached Flask-0.10.1.tar.gz Collecting Werkzeug>=0.7 (from Flask) Downloading Werkzeug-0.11.2-py2.py3-none-any.whl (304kB) 100% |████████████████████████████████| 307kB 671kB/s Collecting Jinja2>=2.4 (from Flask) Using cached Jinja2-2.8-py2.py3-none-any.whl Collecting itsdangerous>=0.21 (from Flask) Using cached itsdangerous-0.24.tar.gz Collecting MarkupSafe (from Jinja2>=2.4->Flask) Using cached MarkupSafe-0.23.tar.gz Building wheels for collected packages: Flask, itsdangerous, MarkupSafe Running setup.py bdist_wheel for Flask Stored in directory: /Users/dierkpol/Library/Caches/pip/wheels/d2/db/61/cb9b80526b8f3ba89248ec0a29d6da1bb6013681c930fca987 Running setup.py bdist_wheel for itsdangerous Stored in directory: /Users/dierkpol/Library/Caches/pip/wheels/97/c0/b8/b37c320ff57e15f993ba0ac98013eee778920b4a7b3ebae3cf Running setup.py bdist_wheel for MarkupSafe Complete output from command /Users/dierkpol/venv3.5/bin/python3 -c "import setuptools;file='/private/var/folders/wc/61klhx9m8xj1b0001s6wbpmr0000gq/T/pip-build-58oqid9o/MarkupSafe/setup.py';exec(compile(open(file).read().replace('\r\n', '\n'), file, 'exec'))" bdist_wheel -d /var/folders/wc/61klhx9m8xj1b0001s6wbpmr0000gq/T/tmpo5iov7pwpip-wheel-: running bdist_wheel running build running build_py creating build creating build/lib.macosx-10.6-intel-3.5

but it does not finish


Failed building wheel for MarkupSafe Successfully built Flask itsdangerous Failed to build MarkupSafe

creating build/temp.macosx-10.6-intel-3.5/c /usr/bin/clang -fno-strict-aliasing -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -I/usr/include/ffi -I/usr/include/libffi -I/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m -c c/cffi_backend.c -o build/temp.macosx-10.6-intel-3.5/c/_cffi_backend.o c/_cffi_backend.c:13:10: fatal error: 'ffi.h' file not found #include <ffi.h> ^ 1 error generated. Note: will not use '_thread' in the C code The above error message can be safely ignored error: command '/usr/bin/clang' failed with exit status 1


Failed building wheel for cffi Failed to build bcrypt cffi Installing collected packages: cffi, six, bcrypt, Flask-bcrypt Running setup.py install for cffi Complete output from command /Users/dierkpol/venv3.5/bin/python3 -c "import setuptools, tokenize;file='/private/var/folders/wc/61klhx9m8xj1b0001s6wbpmr0000gq/T/pip-build-vckp3ely/cffi/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /var/folders/wc/61klhx9m8xj1b0001s6wbpmr0000gq/T/pip-1luzuy4p-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/dierkpol/venv3.5/bin/../include/site/python3.5/cffi: configtest.c:1:1: error: thread-local storage is not supported for the current target __thread int some_threadlocal_variable_42; ^ 1 error generated. running install running build running build_py running build_ext building '_cffi_backend' extension /usr/bin/clang -fno-strict-aliasing -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -I/usr/include/ffi -I/usr/include/libffi -I/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m -c c/_cffi_backend.c -o build/temp.macosx-10.6-intel-3.5/c/_cffi_backend.o c/_cffi_backend.c:13:10: fatal error: 'ffi.h' file not found #include <ffi.h> ^ 1 error generated. Note: will not use '_thread' in the C code The above error message can be safely ignored error: command '/usr/bin/clang' failed with exit status 1

----------------------------------------

Command "/Users/dierkpol/venv3.5/bin/python3 -c "import setuptools, tokenize;file='/private/var/folders/wc/61klhx9m8xj1b0001s6wbpmr0000gq/T/pip-build-vckp3ely/cffi/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /var/folders/wc/61klhx9m8xj1b0001s6wbpmr0000gq/T/pip-1luzuy4p-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/dierkpol/venv3.5/bin/../include/site/python3.5/cffi" failed with error code 1 in /private/var/folders/wc/61klhx9m8xj1b0001s6wbpmr0000gq/T/pip-build-vckp3ely/cffi

I'm getting the same error.

Farrah Dickerson
Farrah Dickerson
10,173 Points
-I/usr/include/ffi -I/usr/include/libffi ...

Looks as if you're missing the ffi library, gents... I use Fedora, but perhaps we can find someone to translate: sudo dnf install libffi-devel OR sudo apt-get install libffi-dev OR sudo apt-get install libffi

This worked for me (linux mint sudo apt-get install libffi-dev). Good call.