Python cryptography: ImportError: No module named setuptools_ext

The error

When you install cryptography with the command pip install cryptography --upgrade, the following error is raised:

``` bash Downloading/unpacking cryptography from https://pypi.python.org/packages/source/c/cryptography/cryptography-1.0.tar.gz#md5=3f2608eb94dcc6e616c3cc2e182181b0 Downloading cryptography-1.0.tar.gz (331kB): 331kB downloaded Running setup.py (path:/tmp/pip_build_root/cryptography/setup.py) egg_info for package cryptography

no previously-included directories found matching 'docs/_build'
warning: no previously-included files matching '*' found under directory 'vectors'

Downloading/unpacking idna>=2.0 (from cryptography) Downloading idna-2.0-py2.py3-none-any.whl (61kB): 61kB downloaded Downloading/unpacking pyasn1>=0.1.8 (from cryptography) Downloading pyasn1-0.1.8.tar.gz (75kB): 75kB downloaded Running setup.py (path:/tmp/pip_build_root/pyasn1/setup.py) egg_info for package pyasn1

Requirement already up-to-date: six>=1.4.1 in /usr/local/lib/python2.7/dist-packages (from cryptography) Downloading/unpacking setuptools from https://pypi.python.org/packages/3.4/s/setuptools/setuptools-18.1-py2.py3-none-any.whl#md5=b6c8eae6b3636dd952e71135805ee156 (from cryptography) Downloading setuptools-18.1-py2.py3-none-any.whl (461kB): 461kB downloaded Requirement already up-to-date: enum34 in /usr/local/lib/python2.7/dist-packages (from cryptography) Downloading/unpacking ipaddress (from cryptography) Downloading ipaddress-1.0.14-py27-none-any.whl Downloading/unpacking cffi>=1.1.0 (from cryptography) Downloading cffi-1.1.2.tar.gz (326kB): 326kB downloaded Running setup.py (path:/tmp/pip_build_root/cffi/setup.py) egg_info for package cffi

Downloading/unpacking pycparser from https://pypi.python.org/packages/source/p/pycparser/pycparser-2.14.tar.gz#md5=a2bc8d28c923b4fe2b2c3b4b51a4f935 (from cffi>=1.1.0->cryptography) Downloading pycparser-2.14.tar.gz (223kB): 223kB downloaded Running setup.py (path:/tmp/pip_build_root/pycparser/setup.py) egg_info for package pycparser

warning: no previously-included files matching 'yacctab.*' found under directory 'tests'
warning: no previously-included files matching 'lextab.*' found under directory 'tests'
warning: no previously-included files matching 'yacctab.*' found under directory 'examples'
warning: no previously-included files matching 'lextab.*' found under directory 'examples'

Installing collected packages: cryptography, idna, pyasn1, setuptools, ipaddress, cffi, pycparser Found existing installation: cryptography 0.7.1 Uninstalling cryptography: Successfully uninstalled cryptography Running setup.py install for cryptography

Installed /tmp/pip_build_root/cryptography/.eggs/cffi-1.1.2-py2.7-linux-x86_64.egg
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip_build_root/cryptography/setup.py", line 307, in <module>
    **keywords_with_side_effects(sys.argv)
  File "/usr/lib/python2.7/distutils/core.py", line 111, in setup
    _setup_distribution = dist = klass(attrs)
  File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 272, in __init__
    _Distribution.__init__(self,attrs)
  File "/usr/lib/python2.7/distutils/dist.py", line 287, in __init__
    self.finalize_options()
  File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 327, in finalize_options
    ep.load()(self, ep.name, value)
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2355, in load
    return self.resolve()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2361, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named setuptools_ext
Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/cryptography/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-X8h31p-record/install-record.txt --single-version-externally-managed --compile:

Installed /tmp/pip_build_root/cryptography/.eggs/cffi-1.1.2-py2.7-linux-x86_64.egg

Traceback (most recent call last):

File "", line 1, in

File "/tmp/pip_build_root/cryptography/setup.py", line 307, in

**keywords_with_side_effects(sys.argv)

File "/usr/lib/python2.7/distutils/core.py", line 111, in setup

_setup_distribution = dist = klass(attrs)

File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 272, in init

_Distribution.__init__(self,attrs)

File "/usr/lib/python2.7/distutils/dist.py", line 287, in init

self.finalize_options()

File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 327, in finalize_options

ep.load()(self, ep.name, value)

File "/usr/local/lib/python2.7/dist-packages/pkg_resources/init.py", line 2355, in load

return self.resolve()

File "/usr/local/lib/python2.7/dist-packages/pkg_resources/init.py", line 2361, in resolve

module = __import__(self.module_name, fromlist=['__name__'], level=0)

ImportError: No module named setuptools_ext


Rolling back uninstall of cryptography ```

# Solution

Install and upgrade the pyhon package cffi:

bash pip install -U cffi