首页 文章

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

提问于
浏览
230

当我尝试通过 pip install cryptography 安装Python的Cryptography包或从their site下载包并运行 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错误帖子(herehere),但那里提供的解决方案无法解决我的问题 . 此外,我可以通过PIP安装其他软件包 .

PIP版本1.5.4 setuptools版本2.2

21 回答

  • 1

    适用于带有MacPorts的El Capitan:

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

    我有一个类似的问题,发现我只是缺少一个依赖(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 and Ubuntu ,以下命令将确保安装所需的依赖项:

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

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

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

    您现在应该能够使用通常的方式构建和安装加密 .

    pip install cryptography
    
  • 0

    这是在密码学的installation docs页面上找到的信息的精简版本 . 有关最新详细信息,请参阅该页面 .

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

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

    Windows

    升级到最新的点子(截至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 or Ubuntu derived distributions

    apt-get install build-essential libssl-dev libffi-dev python-dev 紧随其后

    pip install cryptography

    Red Hat derived distributions

    yum install gcc openssl-devel libffi-devel python-devel 紧随其后

    pip install cryptography

  • 2

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

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

  • 1

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

    显然,在最新版本的OSX上,这可能是因为Apple发布了自己的OpenSSL版本,而OpenSSL不能与加密库一起使用 .

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

    pip install --upgrade --force-reinstall pip virtualenv
    
  • 1

    我怎么解决"Failed cleaning build dir for cryptography"
    (我从谷歌来到这里导致此错误 . )

    note :使用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

    心连心

  • 0

    这对我有用(我使用的是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

  • 14

    Nick Woodham的答案对我来说不适用于OSX 10.11 El Capitan,但是这样做了 .

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

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

  • 4

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

  • 7

    我在运行 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
    
  • 396

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

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

    我实际上遇到了同样的问题,试图安装Scrapy,这取决于首先安装的加密技术 . 我的答案最终对我有用,但首先我必须将 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
    

    它奏效了 .

  • 40

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

  • 22

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

    python setup.py安装

    它完美无缺

    所有默认的pythondev / openssl / libffi包都已存在于rhel中 .

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

  • 3

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

  • 14

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

    sudo apt install libssl1.0
    

    我正在使用Ubuntu 18.04

  • 21

    我有同样的问题:

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

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

    yum install libffi-devel
    
  • 1

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

    brew install openssl
    brew link openssl --force
    

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

相关问题