title: Flask-Bcrypt - AttributeError: 'module' object has no attribute 'ffi' - deployed to AWS Beanstalk
body: <p>I have a Flask application which has been deployed to Ubuntu instances as well as working correctly in my local virtualenv. The issue lies with Flask-Bcrypt, which extends Bcrypt. When I deploy to AWS Beanstalk I receive the follow error:</p>
  
  <pre><code>File "/opt/python/current/app/application.py", line 391, in user_login
  if bc.check_password_hash(user.password, password):
  File "/opt/python/run/venv/lib/python2.7/site-packages/flask_bcrypt.py", line 193, in check_password_hash
  return safe_str_cmp(bcrypt.hashpw(password, pw_hash), pw_hash)
  File "/opt/python/run/venv/lib64/python2.7/site-packages/bcrypt/__init__.py", line 82, in hashpw
  hashed = _bcrypt.ffi.new("char[]", 128)
  AttributeError: 'module' object has no attribute 'ffi'
  </code></pre>
  
  <p>Looking at the <a href="https://github.com/pyca/bcrypt/blob/master/src/build_bcrypt.py" rel="nofollow noreferrer">Bcrypt source code</a> I can see that <code>FFI</code> is imported from <code>cffi</code>:</p>
  
  <pre><code>from cffi import FFI
  </code></pre>
  
  <p>As you can see from my pip output below, <code>cffi==1.9.1</code> is installed. However, if I run <code>which cffi</code> I can see: </p>
  
  <pre><code>no cffi in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin)
  </code></pre>
  
  <p>System info: <code>64bit Amazon Linux 2016.09 v2.3.0 running Python 2.7</code></p>
  
  <p>These packages are installed on <code>eb deploy</code>:</p>
  
  <pre><code>packages:
     yum:
        gcc-c++: []
        python27-devel: []
        gcc: []
        libffi-devel : []
        openssl-devel: []
  </code></pre>
  
  <p>I have seen this issue <a href="https://stackoverflow.com/questions/39980976/python-bcrypt-package-on-heroku-gives-attributeerror-module-object-has-no-att/40133925#40133925">here</a> which suggests a package conflict. However, I do not have <code>py-bcrypt</code> installed. </p>
  
  <p><code>pip freeze</code> returns this following:</p>
  
  <pre><code>aws-cfn-bootstrap==1.4
  aws-elasticbeanstalk-tools==1.19
  awscli==1.11.17
  awscli-cwlogs==1.3.3
  Babel==0.9.4
  backports.ssl-match-hostname==3.4.0.2
  bcrypt==3.1.2
  boto==2.42.0
  botocore==1.4.74
  cffi==1.9.1
  chardet==2.0.1
  click==6.7
  cloud-init==0.7.6
  colorama==0.2.5
  configobj==4.7.2
  cryptography==1.7.1
  docopt==0.4.0
  docutils==0.11
  ecdsa==0.11
  enum34==1.1.6
  Flask==0.12
  Flask-Bcrypt==0.7.1
  futures==3.0.3
  idna==2.2
  iniparse==0.3.1
  ipaddress==1.0.18
  itsdangerous==0.24
  Jinja2==2.7.2
  jmespath==0.9.0
  jsonpatch==1.2
  jsonpointer==1.0
  kitchen==1.1.1
  lockfile==0.8
  mandrill==1.0.57
  MarkupSafe==0.11
  meld3==1.0.2
  paramiko==1.15.1
  PIL==1.1.6
  ply==3.4
  pyasn1==0.1.9
  pycparser==2.17
  pycurl==7.19.0
  pygpgme==0.3
  pyliblzma==0.5.3
  pystache==0.5.3
  python-daemon==1.5.2
  python-dateutil==2.1
  pyxattr==0.5.0
  PyYAML==3.10
  requests==1.2.3
  rsa==3.4.1
  simplejson==3.6.5
  six==1.8.0
  supervisor==3.1.3
  urlgrabber==3.9.1
  urllib3==1.8.2
  virtualenv==12.0.7
  Werkzeug==0.11.15
  yum-metadata-parser==1.1.4
  </code></pre>
  
  <p>Any help greatly appreciated. </p>