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

Failed to install Python Cryptography package with PIP and setup.py

当我尝试通过pip install cryptography安装Python的Cryptography包或从他们的站点下载包并运行python setup.py时,我收到以下错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
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
eq.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
eq.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


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

在Windows上

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

1
2
3
4
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的头文件(如果你的话),那么加密应该很容易在Linux上构建
不使用pypy),以及系统上可用的OpenSSL和libffi库的标头。

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

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

对于Fedora和RHEL衍生产品,以下命令将确保安装所需的依赖项:

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

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

1
pip install cryptography


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

由于这个SO问题不断出现,我也会在这里删除一个响应(我是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


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

1
2
3
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命令合并到以下内容:

1
2
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


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

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

然后它的工作方式如下:

1
2
pip install cryptography
pip install pyopenssl ndg-httpsclient pyasn1


这对El Capitan来说很有用

1
2
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


我是如何解决"为加密清理构建目录失败"的
(我是从谷歌来到这里导致此错误。)

注意:使用virtualenv

TL; DR:

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

说明:

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

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

1
2
3
4
5
6
7
8
9
10
(...)
  ----------------------------------------
  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('

'
, '
'
), __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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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

心连心


显然,在最新版本的OSX上,这可能是因为Apple发布了自己的OpenSSL版本,而这些版本不适用于加密库。

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

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


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

1
sudo apt install libssl1.0

我正在使用Ubuntu 18.04,但它也适用于Ubuntu 18.10。


这对我有用(我使用的是Ubuntu 14.04):

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

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

然后在virtualenv内:

1
2
pip install cryptography
pip install pyopenssl ndg-httpsclient pyasn1

资料来源:

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

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


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

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


我在Ubuntu 16.04上安装cryptography==1.7.1时遇到问题,上面的答案都没有帮助。因此,我将要求升级到兼容的1.8.2并且设置成功。请注意,您仍然需要在顶部(最受欢迎的)答案中提到的构建要点和其他依赖项。


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


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

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

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


这适用于带有MacPorts的El Capitan:

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


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

  • 安装"用于Python的Visual C ++编译器"
  • 打开管理命令提示符窗口
  • 重新运行pip install(包),例如

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

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

    python setup.py安装

    它完美无缺

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

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


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


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


    我实际上遇到了同样的问题,试图安装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的说明从命令行运行以下命令(调整我的配置)...

    1
    2
    3
    4
    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
    2
    3
    4
    5
    6
    7
    pip install cryptography

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

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

    1
    yum install libffi-devel

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


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

    1
    2
    brew install openssl
    brew link openssl --force

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