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

当我尝试通过pip install cryptography安装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错误post( 这里和这里 ),但提供的解决scheme不会解决我的问题。 另外,我可以通过PIP安装其他软件包。

PIP版本1.5.4 setuptools版本2.2

我有一个类似的问题,发现我只是错过了依赖(libssl-dev,对我来说)。 如https://cryptography.io/en/latest/installation/中所述; ,确保符合所有依赖关系:

在Windows上

如果你在Windows上,你需要确保你已经安装了OpenSSL。 有预编译的二进制文件可用。 如果您的安装位于不常见的位置,请将LIB和INCLUDE环境variables设置为包含相应的位置。 例如:

 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上构build密码学

如果你有一个C编译器,Python的头文件(如果你不使用pypy的话)以及你的系统上可用的OpenSSL和libffi库的头文件,那么在Linux上encryption应该很容易。

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

你现在应该可以用通常的方式构build和安装encryption。

 pip install cryptography 

这是密码学安装文档页面上的精简版本。 请参阅该页面了解最新的细节。

既然这个问题不断出现,我也会在这里下载一个响应(我是pyca /encryption开发者之一)。 这就是你需要在三大平台上可靠地安装pyca / cryptography。

请注意,在所有这些情况下强烈build议您安装到virtualenv而不是全局包装空间。 这不是特定于密码学,而是通用build议,以保持您的Python安装可靠。 在OS提供的全局包空间提供的Pythons是由系统所有,并通过点到它安装东西是在寻求麻烦。

视窗

升级到最新点子(截至2016年6月8.1.2),只需pip install cryptography

密码和cffi都是静态链接的轮子。

OS X

升级到最新点子(截至2016年6月8.1.2),只需pip install cryptography

密码和cffi都是静态链接的轮子。 这将适用于pyenv Python,系统Python,自制Python等。只要你在最新的点,你甚至不需要一个编译器。

Linux的

从版本2.0密码学发运manylinux1轮子。 这意味着在基于glibc的发行版(几乎除了Alpine Linux之外的所有内容)以及x86 / x86-64(抱歉的树莓派人)上运行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

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

您可能还想尝试将标志和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 

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

显然,在OSX的最新版本中,这可能是由于苹果发布了自己的版本的OpenSSL,而这些版本并不适用于encryption库。

最近版本的密码术库附带了它们自己的本地依赖项,但是为了得到它们,你需要升级pip,也可能需要虚拟env。 所以对我来说,解决办法是:

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

我如何解决“无法清理构build目录密码学”
(我从谷歌来到这里导致这个错误。)

注意 :使用virtualenv

TL; DR:

我的文件/etc/apt/sources.list没有正确configuration我的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不完全相同的错误,但我最终在这里帮助)

解决:

经过testing几乎每个职位的每一个命令,我最终进行
https://wiki.debian.org/SourcesList
并复制粘贴我的足够的configuration文件/etc/apt/sources.list

然后:

sudo aptitude update

接着

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

接着

pip install cryptography

心连心

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

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

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

这对我工作(我使用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

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

这与MacPorts的El Capitan一起工​​作:

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

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

我实际上遇到了同样的问题,试图安装Scrapy,这取决于首先安装的encryption技术。 我在安装了Python 2.7 64位的Win764位上。 @ jsonm的答案最终为我工作,但首先我必须将C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvarsx86_amd64.bat到该目录中的vcvarsall.bat ,以使vcvarsall.bat停止抛出一个错误,说它缺lessconfiguration。 如果您需要为不同的设置configurationenv vars,请务必将相应的vcvars bat文件复制到相应的subdir,否则下面的第一个命令可能无法正常工作。

然后,我根据@ jsonm的指令(为我的configuration调整)从命令行运行以下内容…

 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 

它的工作。

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

我注意到原来的海报显然是使用Windows安装…以上最好的答案都是其他操作系统…所以在这里。 这假定你已经安装了Python 2.7,这是受到最广泛支持的(尽pipe是旧的)版本。

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

     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

I was having issues with installing cryptography==1.7.1 on Ubuntu 16.04 and none of the answers above helped. So, I upgraded the requirement to a compatible 1.8.2 and the setup was successful. Note that you would still need build essentials & other dependencies mentioned in the accepted answer.

I am having same problem:

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

Then I install libffi-devel and problem is solved

 yum install libffi-devel 

Those two commands fixed it for me:

 brew install openssl brew link openssl --force 

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