无法使用PIP和setup.py安装Python密码术软件包


256

当我尝试通过安装Python 加密程序包pip install cryptography或通过从其站点下载该程序包并运行时python setup.py,出现以下错误:


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错误帖子(此处此处),但是那里提供的解决方案无法解决我的问题。另外,我能够通过PIP安装其他软件包。

PIP版本1.5.4 setuptools版本2.2


每个人的心愿-加密技术现在已经为大多数操作系统提供了预构建轮子,因此pip install加密技术应该可以立即使用。
Legorooj

Answers:


427

我有一个类似的问题,发现我只是缺少一个依赖项(对我来说是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上构建加密

如果您具有C编译器,Python的标头(如果您未使用pypy)以及系统上可用的OpenSSL和libffi库的标头,则加密技术在Linux上应该可以轻松构建。

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

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

对于Fedora和RHEL衍生物,以下命令将确保已安装必需的依赖项:

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

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

pip install cryptography

1
谢谢,做得很好!在拥有VS2010的情况下,我必须:SET VS90COMNTOOLS =%VS100COMNTOOLS%并在库名中添加“ mt”后缀
Maciek,2014年

//,我可以确认它可以在具有Python 3.3的CEntOS 6.3机器上工作,并且错误与原始问题中发布的错误类似。
弥敦道(Nathan Basanese)2015年

4
似乎libffi-dev包是关键。我不需要配置任何其他内容,但是该软件包名称未出现在错误日志中:-/谢谢。
m3nda 2015年

6
如果您使用的是python3,请不要忘记替换python-devpython3-dev
duan

1
FWIW我正在运行Debian 9,不得不做一个apt-get安装libssl1.0-dev,然后我才退出在pip安装加密
Mike Pennington

113

这是在加密技术的安装文档页面上找到的信息的精简版本。请查阅该页面以获取最新详细信息。

由于这个SO问题不断出现,因此我也将在此处做出回应(我是pyca / cryptography开发人员之一)。这是在3个主要平台上可靠地安装pyca / cryptography所需要的。

请注意,在所有这些情况下,强烈建议您安装到virtualenv中,而不要安装到全局软件包空间中。这并非特定于密码学,而是通用建议,以确保您的Python安装可靠。如果Python归系统所有,则OS中的全局程序包空间由系统拥有,并且通过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版开始,密码学附带了许多Linux1轮子。这意味着在基于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

红帽衍生发行版

yum install gcc openssl-devel libffi-devel python-devel 其次是

pip install cryptography


1
我已经做到了,但是我仍然遇到这个错误:“加密的构建轮子失败”,其次是大量输出(太多的评论)。
RolandiXor

4
MacOSX响应在MacOS Sierra 10.12上像魅力一样。目前,我已将点更新为最新版本9.0.1。
若奥·桑托斯

3
升级到最新的pip(截至2016年6月为8.1.2),只需pip安装加密即可!
蒂莫西·道尔顿

我必须手动更新pip已经很久的旧版本,然后OSX解决方案才能发挥作用。(pip 9.0.1MacOS Sierra
benjaminz

1
无法在我的Windows10上运行,无法获得构建错误,无法打开包含文件:“ openssl / opensslv.h”
Totte Karlsson

43

对于那些运行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

1
CFLAGS="-I/usr/include" pip install cryptography 来自reaperhulk的我在Mavericks上为我工作。
jjr4826

答案中的此命令不正确:第二行和第三行必须合并(使用反斜杠)。然后它可以完美运行,只需在El Capitan上进行测试即可。上面的评论也不正确。答案中的其他设置是必需的,否则您将在以后收到投诉。
Christian Tismer

1
一如既往@nathancahill HEHE
Nick Woodhams

1
我必须使用exportnot env,但是可以使用。
理查德

$ ARCHFLAGS="-arch x86_64" LDFLAGS="-L/usr/local/opt/openssl/lib" CFLAGS="-I/usr/local/opt/openssl/include" pip install cryptography工作对我来说在macOS 10.12Python3.7(在virtualenv中)需要时cryptography才能安装ansible
jalanb

23

这在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


这是此页面上的第一个(以及许多其他很多..)在Mojave 10.14.5中为我工作的,谢谢。同样,环境变量仅对命令有效,而对会话无效。
克里斯,

23

这为我解决了问题(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

14

显然,在OSX的最新版本中,这可能是由于Apple发行了自己的OpenSSL版本而导致的,该版本不适用于加密库。

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

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

virtualenv重新安装为我做到了,它使用的是旧版本的pip,但一直失败,谢谢!
Adri Van Houdt

仍然对我失败。OSX 10.11.3 El Capitan在这里。
agondiken '16

14

我如何解决“无法清除用于加密的生成目录”
(我从Google来到这里是导致此错误的结果。)

注意:使用virtualenv

TL; DR:

我的/etc/apt/sources.listDebian 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


解决了我在Ubuntu 16.04服务器上的问题。谢谢
Altaf Hussain

14

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

sudo apt install libssl1.0

我正在使用Ubuntu 18.04,但它也可以在Ubuntu 18.10上运行。


1
尽管此代码可以回答问题,但提供有关如何和/或为什么解决问题的其他上下文将提高​​答案的长期价值。
Nic3500 '18

1
这对我有用。为什么起作用?安装libssl1.0-dev和libssl-dev的软件包之间有什么区别?
克里斯,

2
我不明白为什么,但是只有这也对我有帮助
dyus

也为我工作。虽然在宣布成功安装后pip仍然出现分段错误,但是我认为这只是一个pip问题。
Rob Mosher


7

Nick Woodham的答案对我来说不适用于OSX 10.11 El Capitan,但确实如此。

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

这最适合我,但也失败了。El Capitan OSX 10.11.3在这里。失败,错误代码为/ private / var / folders / d9 / 75cfznt17cjc124j3stq3qc40000gn / T / pip-build-Q_JjdE / cryptography /中的错误代码
agondiken

我必须使用CFLAGS="-I/usr/local/opt/openssl/include" pip install cryptography并安装它。我还必须添加LDFLAGS="-L/usr/local/opt/openssl/lib"才能加载库。克里斯蒂安·阿玛达Dean Christian Armada院长的评论似乎也做同样的事情,只是使用brew生成的变量而不是硬编码。
spig 2016年

4

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



3

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

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

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

由于cffi安装失败,我在pip安装bcrypt时遇到问题,但是这对于cffi和bcrypt均已解决。谢谢!
radiantradon

在El Capitan上,这对我不起作用。另请注意“ pip安装加密”末尾的混乱期。
hacker,2015年

@shacker没有el capitan,所以无法测试,但是消除了流浪期。
ThinkBonobo

@shacker检查我的回答,以了解El Capitan装置的安装
迪安·克里斯蒂安·阿玛达

3

可以在MacPorts的El Capitan上使用:

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

3

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

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

1
干杯,在基于高山的Docker容器中表现出色!
AlexSzabó

2

我注意到原始海报显然是使用Windows安装的...上面的最佳答案都是针对其他操作系统的...所以去了。假设您已经安装了python 2.7,这是最广泛支持(尽管是旧的)的版本。

  1. 安装“适用于Python的Visual C ++编译器
  2. 打开管理命令提示窗口
  3. 重新运行pip安装(程序包),例如

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

2

我最近遇到了类似的问题。就我而言,requirements.txt中的版本cfficryptography写入的版本不兼容(cffi == 1.8.9和cryptography == 1.9)。我解决cffi了使用最新可用版本进行更新的问题。


1

我实际上遇到了同样的问题,试图安装Scrapy,这取决于首先安装的加密技术。我使用的是Win764位,安装了Python 2.7 64位。@jsonm的答案最终对我有用,但首先我必须复制C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvarsx86_amd64.bat到该x86_amd64bin目录中的子目录,以便vcvarsall.bat才会停止抛出错误,指出它缺少配置。如果您需要为其他设置配置环境变量,请确保将相应的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

而且有效。



1

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

python setup.py安装

它完美地工作

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

下载rpm时rpm不匹配且麻烦更多


0

我有同样的问题:

pip install cryptography

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

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

yum install libffi-devel


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.