无法使用PIP和setup.py安装Python Cryptography包

时间:2014-02-27 15:50:28

标签: python cryptography pip

当我尝试通过pip install cryptography安装Python的Cryptography包或从their site下载并运行python setup.py时,我收到以下错误:< / p>


D:\Anaconda\Scripts\pip-script.py run on 02/27/14 16:13:17
Downloading/unpacking cryptography
  Getting page https://pypi.python.org/simple/cryptography/
  URLs to search for versions for cryptography:
  * https://pypi.python.org/simple/cryptography/
  Analyzing links from page https://pypi.python.org/simple/cryptography/
    Skipping https://pypi.python.org/packages/cp26/c/cryptography/cryptography-0.2-cp26-none-win32.whl#md5=13e5c4b19520e7dc6f07c6502b3f74e2 (from https://pypi.python.org/simple/cryptography/) because it is not compatible with this Python
    Skipping https://pypi.python.org/packages/cp26/c/cryptography/cryptography-0.2.1-cp26-none-win32.whl#md5=00e733648ee5cdb9e58876238b1328f8 (from https://pypi.python.org/simple/cryptography/) because it is not compatible with this Python
    Skipping https://pypi.python.org/packages/cp27/c/cryptography/cryptography-0.2-cp27-none-win32.whl#md5=013ccafa6a5a3ea92c73f2c1c4879406 (from https://pypi.python.org/simple/cryptography/) because it is not compatible with this Python
    Skipping https://pypi.python.org/packages/cp27/c/cryptography/cryptography-0.2.1-cp27-none-win32.whl#md5=127d6a5dc687250721f892d55720a06c (from https://pypi.python.org/simple/cryptography/) because it is not compatible with this Python
    Skipping https://pypi.python.org/packages/cp32/c/cryptography/cryptography-0.2-cp32-none-win32.whl#md5=051424a36e91039807b72f112333ded3 (from https://pypi.python.org/simple/cryptography/) because it is not compatible with this Python
    Skipping https://pypi.python.org/packages/cp32/c/cryptography/cryptography-0.2.1-cp32-none-win32.whl#md5=53f6f57db8e952d64283baaa14cbde3d (from https://pypi.python.org/simple/cryptography/) because it is not compatible with this Python
    Skipping https://pypi.python.org/packages/cp33/c/cryptography/cryptography-0.2-cp33-none-win32.whl#md5=302812c1c1a035cf9ba3292f8dbf3f9e (from https://pypi.python.org/simple/cryptography/) because it is not compatible with this Python
    Skipping https://pypi.python.org/packages/cp33/c/cryptography/cryptography-0.2.1-cp33-none-win32.whl#md5=81acca90caf8a45f2ca73f3f9859fae4 (from https://pypi.python.org/simple/cryptography/) because it is not compatible with this Python
    Found link https://pypi.python.org/packages/source/c/cryptography/cryptography-0.1.tar.gz#md5=bdc1c5fe069deca7467b71a0cc538f17 (from https://pypi.python.org/simple/cryptography/), version: 0.1
    Found link https://pypi.python.org/packages/source/c/cryptography/cryptography-0.2.1.tar.gz#md5=872fc04268dadc66a0305ae5ab1c123b (from https://pypi.python.org/simple/cryptography/), version: 0.2.1
    Found link https://pypi.python.org/packages/source/c/cryptography/cryptography-0.2.tar.gz#md5=8a3d21e837a21e1b7634ee1f22b06bb6 (from https://pypi.python.org/simple/cryptography/), version: 0.2
  Using version 0.2.1 (newest of versions: 0.2.1, 0.2, 0.1)
  Downloading from URL https://pypi.python.org/packages/source/c/cryptography/cryptography-0.2.1.tar.gz#md5=872fc04268dadc66a0305ae5ab1c123b (from https://pypi.python.org/simple/cryptography/)
  Running setup.py (path:c:\users\paco\appdata\local\temp\pip_build_Paco\cryptography\setup.py) egg_info for package cryptography
    In file included from c/_cffi_backend.c:7:0:
    c/misc_win32.h:225:23: error: two or more data types in declaration specifiers
    c/misc_win32.h:225:1: warning: useless type name in empty declaration [enabled by default]
    c/_cffi_backend.c: In function 'convert_array_from_object':
    c/_cffi_backend.c:1105:26: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1105:26: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c:1130:30: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1130:30: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c:1150:30: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1150:30: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c: In function 'convert_struct_from_object':
    c/_cffi_backend.c:1183:26: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1183:26: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c:1196:30: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1196:30: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c: In function 'cdata_repr':
    c/_cffi_backend.c:1583:13: warning: unknown conversion type character 'L' in format [-Wformat]
    c/_cffi_backend.c:1583:13: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c:1595:9: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1595:9: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c: In function 'cdataowning_repr':
    c/_cffi_backend.c:1647:30: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1647:30: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c: In function '_cdata_get_indexed_ptr':
    c/_cffi_backend.c:1820:26: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1820:26: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1820:26: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c: In function '_cdata_getslicearg':
    c/_cffi_backend.c:1872:26: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1872:26: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1872:26: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c: In function 'cdata_ass_slice':
    c/_cffi_backend.c:1951:26: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1951:26: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1951:26: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c:1969:30: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1969:30: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1969:30: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c:1983:22: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:1983:22: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c: In function 'cdata_call':
    c/_cffi_backend.c:2367:30: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:2367:30: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'Py_ssize_t' [-Wformat]
    c/_cffi_backend.c:2367:30: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c: In function 'cast_to_integer_or_char':
    c/_cffi_backend.c:2916:26: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:2916:26: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'Py_ssize_t' [-Wformat]
    c/_cffi_backend.c:2916:26: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c:2928:26: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:2928:26: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'Py_ssize_t' [-Wformat]
    c/_cffi_backend.c:2928:26: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c: In function 'new_array_type':
    c/_cffi_backend.c:3480:9: warning: unknown conversion type character 'l' in format [-Wformat]
    c/_cffi_backend.c:3480:9: warning: too many arguments for format [-Wformat-extra-args]
    c/_cffi_backend.c: In function 'b_complete_struct_or_union':
    c/_cffi_backend.c:3878:22: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:3878:22: warning: unknown conversion type character 'z' in format [-Wformat]
    c/_cffi_backend.c:3878:22: warning: too many arguments for format [-Wformat-extra-args]
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "c:\users\paco\appdata\local\temp\pip_build_Paco\cryptography\setup.py", line 113, in <module>
        "build": cffi_build,
      File "D:\Anaconda\lib\distutils\core.py", line 112, in setup
        _setup_distribution = dist = klass(attrs)
      File "build\bdist.win-amd64\egg\setuptools\dist.py", line 239, in __init__
      File "build\bdist.win-amd64\egg\setuptools\dist.py", line 264, in fetch_build_eggs
      File "build\bdist.win-amd64\egg\pkg_resources.py", line 580, in resolve
        dist = best[req.key] = env.best_match(req, ws, installer)
      File "build\bdist.win-amd64\egg\pkg_resources.py", line 818, in best_match
        return self.obtain(req, installer) # try and download/install
      File "build\bdist.win-amd64\egg\pkg_resources.py", line 830, in obtain
        return installer(requirement)
      File "build\bdist.win-amd64\egg\setuptools\dist.py", line 314, in fetch_build_egg
      File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 593, in easy_install

      File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 623, in install_item

      File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 809, in install_eggs

      File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 1015, in build_and_install

      File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 1003, in run_setup

    distutils.errors.DistutilsError: Setup script exited with error: command 'gcc' failed with exit status 1
    Complete output from command python setup.py egg_info:
    In file included from c/_cffi_backend.c:7:0:

c/misc_win32.h:225:23: error: two or more data types in declaration specifiers

c/misc_win32.h:225:1: warning: useless type name in empty declaration [enabled by default]

c/_cffi_backend.c: In function 'convert_array_from_object':

c/_cffi_backend.c:1105:26: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1105:26: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c:1130:30: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1130:30: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c:1150:30: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1150:30: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c: In function 'convert_struct_from_object':

c/_cffi_backend.c:1183:26: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1183:26: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c:1196:30: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1196:30: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c: In function 'cdata_repr':

c/_cffi_backend.c:1583:13: warning: unknown conversion type character 'L' in format [-Wformat]

c/_cffi_backend.c:1583:13: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c:1595:9: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1595:9: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c: In function 'cdataowning_repr':

c/_cffi_backend.c:1647:30: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1647:30: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c: In function '_cdata_get_indexed_ptr':

c/_cffi_backend.c:1820:26: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1820:26: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1820:26: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c: In function '_cdata_getslicearg':

c/_cffi_backend.c:1872:26: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1872:26: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1872:26: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c: In function 'cdata_ass_slice':

c/_cffi_backend.c:1951:26: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1951:26: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1951:26: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c:1969:30: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1969:30: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1969:30: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c:1983:22: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:1983:22: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c: In function 'cdata_call':

c/_cffi_backend.c:2367:30: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:2367:30: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'Py_ssize_t' [-Wformat]

c/_cffi_backend.c:2367:30: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c: In function 'cast_to_integer_or_char':

c/_cffi_backend.c:2916:26: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:2916:26: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'Py_ssize_t' [-Wformat]

c/_cffi_backend.c:2916:26: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c:2928:26: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:2928:26: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'Py_ssize_t' [-Wformat]

c/_cffi_backend.c:2928:26: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c: In function 'new_array_type':

c/_cffi_backend.c:3480:9: warning: unknown conversion type character 'l' in format [-Wformat]

c/_cffi_backend.c:3480:9: warning: too many arguments for format [-Wformat-extra-args]

c/_cffi_backend.c: In function 'b_complete_struct_or_union':

c/_cffi_backend.c:3878:22: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:3878:22: warning: unknown conversion type character 'z' in format [-Wformat]

c/_cffi_backend.c:3878:22: warning: too many arguments for format [-Wformat-extra-args]

Traceback (most recent call last):

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

  File "c:\users\paco\appdata\local\temp\pip_build_Paco\cryptography\setup.py", line 113, in <module>

    "build": cffi_build,

  File "D:\Anaconda\lib\distutils\core.py", line 112, in setup

    _setup_distribution = dist = klass(attrs)

  File "build\bdist.win-amd64\egg\setuptools\dist.py", line 239, in __init__

  File "build\bdist.win-amd64\egg\setuptools\dist.py", line 264, in fetch_build_eggs

  File "build\bdist.win-amd64\egg\pkg_resources.py", line 580, in resolve

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

  File "build\bdist.win-amd64\egg\pkg_resources.py", line 818, in best_match

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

  File "build\bdist.win-amd64\egg\pkg_resources.py", line 830, in obtain

    return installer(requirement)

  File "build\bdist.win-amd64\egg\setuptools\dist.py", line 314, in fetch_build_egg

  File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 593, in easy_install



  File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 623, in install_item



  File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 809, in install_eggs



  File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 1015, in build_and_install



  File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 1003, in run_setup



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

----------------------------------------
Cleaning up...
  Removing temporary dir c:\users\paco\appdata\local\temp\pip_build_Paco...
Command python setup.py egg_info failed with error code 1 in c:\users\paco\appdata\local\temp\pip_build_Paco\cryptography
Exception information:
Traceback (most recent call last):
  File "D:\Anaconda\lib\site-packages\pip-1.5.4-py2.7.egg\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "D:\Anaconda\lib\site-packages\pip-1.5.4-py2.7.egg\pip\commands\install.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "D:\Anaconda\lib\site-packages\pip-1.5.4-py2.7.egg\pip\req.py", line 1229, in prepare_files
    req_to_install.run_egg_info()
  File "D:\Anaconda\lib\site-packages\pip-1.5.4-py2.7.egg\pip\req.py", line 325, in run_egg_info
    command_desc='python setup.py egg_info')
  File "D:\Anaconda\lib\site-packages\pip-1.5.4-py2.7.egg\pip\util.py", line 697, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command python setup.py egg_info failed with error code 1 in c:\users\paco\appdata\local\temp\pip_build_Paco\cryptography

我发现了其他egg_info错误帖子(herehere)但是提供的解决方案无法解决我的问题。此外,我可以通过PIP安装其他软件包。

PIP版本1.5.4 setuptools版本2.2

27 个答案:

答案 0 :(得分:404)

我有一个类似的问题,发现我只是缺少一个依赖(libssl-dev,对我而言)。正如https://cryptography.io/en/latest/installation/中所述,确保满足所有依赖性:

在Windows上

如果您使用的是Windows,则需要确保已安装OpenSSL。有预编译的二进制文件可用。如果您的安装位于异常位置,请将LIB和INCLUDE环境变量设置为包含 相应的位置。例如:

C:\> \path\to\vcvarsall.bat x86_amd64
C:\> set LIB=C:\OpenSSL-1.0.1f-64bit\lib;%LIB%
C:\> set INCLUDE=C:\OpenSSL-1.0.1f-64bit\include;%INCLUDE%
C:\> pip install cryptography

在Linux上构建加密

加密应该在Linux上很容易构建,前提是你有一个C编译器,Python的头文件(如果你的话) 不使用pypy),以及系统上可用的OpenSSL和libffi库的标题。

对于 Debian和Ubuntu ,以下命令将确保安装所需的依赖项:

sudo apt-get install build-essential libssl-dev libffi-dev python-dev

对于 Fedora和RHEL-derivatives ,以下命令将确保安装所需的依赖项:

sudo yum install gcc libffi-devel python-devel openssl-devel

您现在应该可以使用通常的方式构建和安装加密。

pip install cryptography

答案 1 :(得分:102)

这是在加密的installation文档页面上找到的信息的精简版本。有关最新详细信息,请参阅该页面。

由于这个问题不断出现,我也会在这里放弃回复(我是pyca /加密开发人员之一)。以下是在3个主要平台上可靠地安装pyca / cryptography所需的内容。

请注意,在所有这些情况下,您强烈建议将强烈推荐安装到virtualenv中,而不是安装到全局包空间中。这不是特定于加密,而是保持Python安装可靠的通用建议。操作系统中的全局程序包空间提供了Pythons由系统拥有,并通过pip安装到它中是一件麻烦。

<强>窗

升级到最新的点子(截至2016年6月的8.1.2)和pip install cryptography

密码学和cffi都作为静态链接轮运送。

OS X

升级到最新的点子(截至2016年6月的8.1.2)和pip install cryptography

密码学和cffi都作为静态链接轮运输。这适用于pyenv Python,系统Python,自制Python等。只要您使用的是最新的pip,您甚至不需要编译器。

<强>的Linux

从版本2.0开始加密manylinux1轮子。这意味着在基于glibc的发行版(几乎所有除Alpine Linux之外的所有内容)和x86 / x86-64(抱歉Raspberry Pi人)上运行的pip 8.1+的用户不再需要编译器或头文件,因为您将自动获得预编译的轮子。所以,首先你应该尝试升级你的点子!

如果你不是manylinux1兼容,那么这就是你需要做的事情:

你需要一个C编译器,libffi +它的开发头文件,以及openssl +它的开发头文件。

Debian或Ubuntu派生的发行版

apt-get install build-essential libssl-dev libffi-dev python-dev后跟

pip install cryptography

Red Hat派生的发行版

yum install gcc openssl-devel libffi-devel python-devel后跟

pip install cryptography

答案 2 :(得分:40)

对于那些运行OS X的人来说,这对我有用:

brew install openssl
env ARCHFLAGS="-arch x86_64" LDFLAGS="-L/usr/local/opt/openssl/lib" CFLAGS="-I/usr/local/opt/openssl/include"
pip install cryptography

(跑10.9小牛队)

您可能还想根据以下注释尝试将flags和pip命令合并到以下内容:

brew install openssl
env ARCHFLAGS="-arch x86_64" LDFLAGS="-L/usr/local/opt/openssl/lib" CFLAGS="-I/usr/local/opt/openssl/include" pip install cryptography

答案 3 :(得分:22)

这解决了我的问题(Ubuntu 16.04):

sudo apt-get install build-essential libssl-dev libffi-dev python-dev python3-dev

然后它的工作方式如下:

pip install cryptography
pip install pyopenssl ndg-httpsclient pyasn1

答案 4 :(得分:22)

这在El Capitan为我工作

brew install pkg-config libffi openssl
env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" pip install cryptography

您还可以在此处查看帖子:https://github.com/pyca/cryptography/issues/2350

答案 5 :(得分:14)

显然,在最新版本的OSX上,这可能是因为Apple发布了他们自己的OpenSSL版本,而后者无法使用加密库。

最近版本的加密库附带了他们自己的本机依赖项,​​但要获得它们,您需要升级pip,也可能还需要虚拟环境。所以对我来说,解决方案是:

pip install --upgrade --force-reinstall pip virtualenv

答案 6 :(得分:14)

我如何解决&#34;无法清除加密的构建目录&#34;
(我从谷歌来到这里导致此错误。)

注意:使用virtualenv

TL; DR:

我的文件/etc/apt/sources.list没有为我的debian 8正确配置。

说明:

我想安装paramiko。 paramiko需要密码学。

我收到了这些错误: 首先使用pip install cryptography

(...)
  ----------------------------------------
  Failed cleaning build dir for cryptography
Failed to build cryptography
(...)
    ----------------------------------------
Command "/home/myuser/pyenvs/testo/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-HXWKAO/cryptography/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-WjqY6V-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/myuser/pyenvs/testo/include/site/python2.7/cryptography" failed with error code 1 in /tmp/pip-build-HXWKAO/cryptography/

然后使用sudo apt-get install build-essential

Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 build-essential : Depends: libc6-dev but it is not going to be installed > or
                            libc-dev
                   Depends: gcc (>= 4:4.4.3) but it is not going to be installed
                   Depends: g++ (>= 4:4.4.3) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

(与OP不完全相同的错误,但我在这里帮助最终

求解:

在对每个帖子中的几乎所有命令进行测试之后,我最终会继续进行测试 https://wiki.debian.org/SourcesList
并在文件/etc/apt/sources.list

中复制粘贴我的足够配置

然后:

sudo aptitude update

然后

sudo apt-get install build-essential libssl-dev libffi-dev python-dev

然后

pip install cryptography

HTH

答案 7 :(得分:10)

这对我有用(我正在使用Ubuntu 14.04):

首先安装libffi-dev libssl-dev libpython2.7-dev:

sudo apt-get install libffi-dev libssl-dev libpython2.7-dev

然后在virtualenv里面:

pip install cryptography
pip install pyopenssl ndg-httpsclient pyasn1

来源:

https://stackoverflow.com/a/32800685/5123544

https://stackoverflow.com/a/29202163/5123544

答案 8 :(得分:7)

我在上面尝试了许多解决方案,但是只有在安装以下lib之后,我才能安装cryptography

sudo apt install libssl1.0

我正在使用Ubuntu 18.04

答案 9 :(得分:7)

Nick Woodham的回答并没有为我提供OSX 10.11 El Capitan的帮助,但确实如此。

brew install openssl
CFLAGS="-I/usr/local/opt/openssl/include" pip install cryptography==0.8

答案 10 :(得分:4)

我在Ubuntu 16.04上安装cryptography==1.7.1时遇到问题,上面的答案都没有帮助。因此,我将需求升级到compatible 1.8.2并且设置成功。请注意,您仍然需要构建必需品和top (most upvoted) answer中提到的其他依赖项。

答案 11 :(得分:4)

如果您使用的是python3,则需要安装python3-dev。这解决了我的问题sudo apt-get install python3-dev

答案 12 :(得分:4)

如果要在 .gitlab-ci.yml 文件中为使用部署在AWS EC2机器中的gitlab运行器的GitLab CI构建python软件包分发

 - apk add --update alpine-sdk && \
 - apk add libffi-dev openssl-dev && \
 - apk --no-cache --update add build-base

答案 13 :(得分:3)

适用于带有MacPorts的El Capitan:

$ sudo port install openssl
$ env LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" pip install cryptography

答案 14 :(得分:3)

我遇到运行sudo pip install cryptography的问题,因为在尝试编译时找不到ffi。 (OSX - Yosemite)

我通过下载libffi并设置env var来解决它。

$ brew install pkg-config libffi
$ export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/
$ pip install cryptography

答案 15 :(得分:2)

我注意到原来的海报明显使用了Windows安装......上面的最佳答案都适用于其他操作系统......所以这里有。这假设您已经安装了Python 2.7,这是受支持最广泛的版本(尽管旧版本)。

  1. 安装&#34; Visual C++ Compiler for Python&#34;
  2. 打开管理命令提示符窗口
  3. 重新运行pip install(package),例如

    cd C:\Python27\Scripts
    pip install cryptography  (or pycrypto, fabric, etc)
    

答案 16 :(得分:2)

如果要对python应用程序进行docker化,则Dockerfile需要具有以下内容:

从python:3.7-高山

运行apk添加--update alpine-sdk && apk添加libffi-dev openssl-dev

运行pip安装密码

答案 17 :(得分:1)

改用conda

Raspbian 10 (buster) 上,所有建议的解决方案都不适合我,所以我只是通过 conda 安装了它,瞧:

conda install -c anaconda cryptography

P.S. :我知道问题提到了 pip,但我看到 OP 正在使用 conda 安装,所以我还是想分享这个解决方案。尽管如此,由于这个问题显然是特定于操作系统的,因此提醒人们 conda 是一种跨平台且与语言无关的解决方案是有意义的,除了 python 包外,它还可以安装必要的二进制文件 - 只需一个单行。

答案 18 :(得分:1)

我实际上遇到了同样的问题,试图安装Scrapy,这取决于首先安装的加密技术。我在安装了Python 2.7 64位的Win764位上运行。 @jsonm的答案最终对我有用,但首先我必须将C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvarsx86_amd64.bat复制到该bin目录中的x86_amd64子目录,以便vcvarsall.bat停止抛出错误,说它是错过了配置。如果您需要为不同的设置配置env vars,请确保将相应的vcvars bat文件复制到相应的子目录,否则下面的第一个命令可能无效。

然后我根据@jsonm的说明从命令行运行以下命令(调整我的配置)......

C:\> "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86_amd64 
C:\> set LIB=C:\OpenSSL-Win64\lib;%LIB% 
C:\> set INCLUDE=C:\OpenSSL-Win64\include;%INCLUDE% 
C:\> pip install cryptography

它有效。

答案 19 :(得分:1)

我最近遇到了类似的问题。在我的例子中,在requirements.txt中编写的cfficryptography版本不兼容(cffi == 1.8.9和cryptography == 1.9)。我解决了使用上一个可用版本更新cffi的问题。

答案 20 :(得分:1)

我从pypi下载了paramiko完整的源代码并且做了

python setup.py install

它完美无缺地运作

rhel中已经存在所有默认的pythondev / openssl / libffi包。

下载rpms有rpm不匹配和更多麻烦

答案 21 :(得分:1)

我也有这个错误。在安装openSSL之后继续出现此错误之后,我最终尝试从https://pypi.python.org/pypi/cryptography/0.2.2#downloads的wheel文件进​​行安装。它奏效了!

答案 22 :(得分:0)

我通过从加密1.9升级到2.4.2来解决了这个问题

答案 23 :(得分:0)

这两个命令为我修复了它:

for(int i = 2, j = 2*i, k = 4*j ; i < 3 ; i++) {
    System.out.println(i + " " + j + " " + k); // 2 4 16
}

来源:https://github.com/phusion/passenger/issues/1630#issuecomment-147527656

答案 24 :(得分:0)

在Cygwin中遇到了同样的问题,这对我有帮助

sudo apt-get install python-pip python-dev libffi-dev libssl-dev libxml2-dev libxslt1-dev libjpeg8-dev zlib1g-dev

但是我不是通过sudo apt-get install而是通过Cygwin安装了这些软件包 Source of this code

答案 25 :(得分:0)

我遇到同样的问题:

pip install cryptography

.
.
.
Installing collected packages: cffi, cryptography
     Running setup.py install for cffi ... error

然后我安装了libffi-devel并解决了问题

yum install libffi-devel

答案 26 :(得分:0)

您必须在运行安装之前升级您的 pip