Ansible 2.x install fails due to paramiko 2.0 depe

2019-07-21 02:51发布

问题:

Installing the latest Ansible via pip fails due to paramiko 2.0 changing their dependency from pycrypto to cryptography. Cryptography has a dependency on cffi, which requires libffi-dev. Does anyone know how to fix this? (Ubuntu Trusty 14.04)

RUN pip install --upgrade ansible
 ---> Running in 8ef89649c480
Collecting ansible
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading ansible-2.0.2.0.tar.gz (1.5MB)
Collecting paramiko (from ansible)
  Downloading paramiko-2.0.0-py2.py3-none-any.whl (170kB)
Collecting jinja2 (from ansible)
  Downloading Jinja2-2.8-py2.py3-none-any.whl (263kB)
Collecting PyYAML (from ansible)
  Downloading PyYAML-3.11.zip (371kB)
Collecting setuptools (from ansible)
  Downloading setuptools-21.2.1-py2.py3-none-any.whl (509kB)
Collecting pycrypto>=2.6 (from ansible)
  Downloading pycrypto-2.6.1.tar.gz (446kB)
Collecting cryptography>=1.1 (from paramiko->ansible)
  Downloading cryptography-1.3.2.tar.gz (383kB)
Collecting pyasn1>=0.1.7 (from paramiko->ansible)
  Downloading pyasn1-0.1.9-py2.py3-none-any.whl
Collecting MarkupSafe (from jinja2->ansible)
  Downloading MarkupSafe-0.23.tar.gz
Collecting idna>=2.0 (from cryptography>=1.1->paramiko->ansible)
  Downloading idna-2.1-py2.py3-none-any.whl (54kB)
Collecting six>=1.4.1 (from cryptography>=1.1->paramiko->ansible)
  Downloading six-1.10.0-py2.py3-none-any.whl
Collecting enum34 (from cryptography>=1.1->paramiko->ansible)
  Downloading enum34-1.1.6-py2-none-any.whl
Collecting ipaddress (from cryptography>=1.1->paramiko->ansible)
  Downloading ipaddress-1.0.16-py27-none-any.whl
Collecting cffi>=1.4.1 (from cryptography>=1.1->paramiko->ansible)
  Downloading cffi-1.6.0.tar.gz (397kB)
Collecting pycparser (from cffi>=1.4.1->cryptography>=1.1->paramiko->ansible)
  Downloading pycparser-2.14.tar.gz (223kB)
Building wheels for collected packages: ansible, PyYAML, pycrypto, cryptography, MarkupSafe, cffi, pycparser
  Running setup.py bdist_wheel for ansible: started
  Running setup.py bdist_wheel for ansible: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/7a/56/e4/5dbcf0564a8cad5175b8c85bb123fdc81ad48bd31d27ac6011
  Running setup.py bdist_wheel for PyYAML: started
  Running setup.py bdist_wheel for PyYAML: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/4a/bf/14/d79994d19a59d4f73efdafb8682961f582d45ed6b459420346
  Running setup.py bdist_wheel for pycrypto: started
  Running setup.py bdist_wheel for pycrypto: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/80/1f/94/f76e9746864f198eb0e304aeec319159fa41b082f61281ffce
  Running setup.py bdist_wheel for cryptography: started
  Running setup.py bdist_wheel for cryptography: finished with status 'error'
  Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-U7yVav/cryptography/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpQA7GLCpip-wheel- --python-tag cp27:
  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
  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
  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
  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
  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
  No package 'libffi' found
  c/_cffi_backend.c:15:17: fatal error: ffi.h: No such file or directory
   #include <ffi.h>
                   ^
  compilation terminated.
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-build-U7yVav/cryptography/setup.py", line 335, 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/lib/python2.7/dist-packages/setuptools/dist.py", line 239, in __init__
      self.fetch_build_eggs(attrs.pop('setup_requires'))
    File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 264, in fetch_build_eggs
      replace_conflicting=True
    File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 620, in resolve
      dist = best[req.key] = env.best_match(req, ws, installer)
    File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 858, in best_match
      return self.obtain(req, installer) # try and download/install
    File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 870, in obtain
      return installer(requirement)
    File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 314, in fetch_build_egg
      return cmd.easy_install(req)
    File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 616, in easy_install
      return self.install_item(spec, dist.location, tmpdir, deps)
    File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 646, in install_item
      dists = self.install_eggs(spec, download, tmpdir)
    File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 834, in install_eggs
      return self.build_and_install(setup_script, setup_base)
    File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1040, in build_and_install
      self.run_setup(setup_script, setup_base, args)
    File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1028, in run_setup
      raise DistutilsError("Setup script exited with %s" % (v.args[0],))
  distutils.errors.DistutilsError: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for cryptography
  Running setup.py clean for cryptography
  Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-U7yVav/cryptography/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" clean --all:
  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
  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
  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
  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
  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
  No package 'libffi' found
  c/_cffi_backend.c:15:17: fatal error: ffi.h: No such file or directory
   #include <ffi.h>
                   ^
  compilation terminated.
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-build-U7yVav/cryptography/setup.py", line 335, 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/lib/python2.7/dist-packages/setuptools/dist.py", line 239, in __init__
      self.fetch_build_eggs(attrs.pop('setup_requires'))
    File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 264, in fetch_build_eggs
      replace_conflicting=True
    File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 620, in resolve
      dist = best[req.key] = env.best_match(req, ws, installer)
    File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 858, in best_match
      return self.obtain(req, installer) # try and download/install
    File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 870, in obtain
      return installer(requirement)
    File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 314, in fetch_build_egg
      return cmd.easy_install(req)
    File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 616, in easy_install
      return self.install_item(spec, dist.location, tmpdir, deps)
    File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 646, in install_item
      dists = self.install_eggs(spec, download, tmpdir)
    File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 834, in install_eggs
      return self.build_and_install(setup_script, setup_base)
    File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1040, in build_and_install
      self.run_setup(setup_script, setup_base, args)
    File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1028, in run_setup
      raise DistutilsError("Setup script exited with %s" % (v.args[0],))
  distutils.errors.DistutilsError: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

回答1:

To install cryptography >= 1.1 from pip, you need to install the developer package for libffi since it will contain the missing header file. Since you tagged Ubuntu, I am assuming you are using the apt package manager.

apt-get install libffi-dev

You will also need your distro's equivalent of ssl's development package and gcc for cryptography >= 1.1. If you are running this in your system environment then gcc is almost certainly already installed, but you may need to apt-get install libssl-dev also if that is missing.

The Fedora/RHEL equivalents are libffi-devel and openssl-devel, and can be installed with dnf or yum depending on your OS and version.



回答2:

Found one solution is to install specific versions of each:

pip install paramiko==1.17.0 ansible==2.0.0.2