Python 如何在 ubuntu 上安装密码学?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35144550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 16:03:06  来源:igfitidea点击:

How to install cryptography on ubuntu?

pythonubuntucryptographypip

提问by ithelloworld

My ubuntu is 14.04 LTS.

我的 ubuntu 是 14.04 LTS。

When I install cryptography, the error is:

当我安装加密时,错误是:

Installing egg-scripts.
uses namespace packages but the distribution does not require setuptools.
Getting distribution for 'cryptography==0.2.1'.

no previously-included directories found matching 'documentation/_build'
zip_safe flag not set; analyzing archive contents...
six: module references __path__

Installed /tmp/easy_install-oUz7ei/cryptography-0.2.1/.eggs/six-1.10.0-py2.7.egg
Searching for cffi>=0.8
Reading https://pypi.python.org/simple/cffi/
Best match: cffi 1.5.0
Downloading https://pypi.python.org/packages/source/c/cffi/cffi-1.5.0.tar.gz#md5=dec8441e67880494ee881305059af656
Processing cffi-1.5.0.tar.gz
Writing /tmp/easy_install-oUz7ei/cryptography-0.2.1/temp/easy_install-Yf2Yl3/cffi-1.5.0/setup.cfg
Running cffi-1.5.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-oUz7ei/cryptography-0.2.1/temp/easy_install-Yf2Yl3/cffi-1.5.0/egg-dist-tmp-A2kjMD
c/_cffi_backend.c:15:17: fatal error: ffi.h: No such file or directory
 #include <ffi.h>
                 ^
compilation terminated.
error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
An error occurred when trying to install cryptography 0.2.1. Look above this message for any errors that were output by easy_install.
While:
  Installing egg-scripts.
  Getting distribution for 'cryptography==0.2.1'.
Error: Couldn't install: cryptography 0.2.1

I don't know why it was failed. What is the reason. Is there something necessary when install it on ubuntu system?

我不知道为什么它失败了。是什么原因。在 ubuntu 系统上安装时有什么必要吗?

回答by Angelos

I had the same problem when pip installing the cryptography module on Ubuntu 14.04. I solved it by installing libffi-dev:

在 Ubuntu 14.04 上 pip 安装加密模块时,我遇到了同样的问题。我通过安装 libffi-dev 解决了它:

apt-get install -y libffi-dev

Then I got the following error:

然后我收到以下错误:

build/temp.linux-x86_64-3.4/_openssl.c:431:25: fatal error: openssl/aes.h: No such file or directory
 #include <openssl/aes.h>
                         ^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Which I resolved by installing libssl-dev:

我通过安装 libssl-dev 解决了这个问题:

apt-get install -y libssl-dev

回答by kmonsoor

The answer is on the docs of cryptography's installation sectionwhich pretty much reflects Angelos' answer:

答案是对的文档cryptography安装部分,这几乎反映了Angelos的回答:

Quoting it:

引用它:

For Debian and Ubuntu, the following command will ensure that the required dependencies are installed:

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

For Fedora and RHEL-derivatives, the following command will ensure that the required dependencies are installed:

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

You should now be able to build and install cryptography with the usual

$ pip install cryptography

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

If you're using Python 3, please use python3-devinstead of python-devin the first command. (thanks to @chasmani)

如果您使用的是 Python 3,请在第一个命令中使用python3-dev代替python-dev。(感谢@chasmani)

If you're installing this on Ubuntu 18.04, please use libssl1.0instead of libssl-devin the first command. (thanks to @pobe)

如果您在 上安装它Ubuntu 18.04,请在第一个命令中使用libssl1.0而不是libssl-dev。(感谢@pobe)

回答by Renato Prado

Installing libssl-dev and python-dev was enough for me on ubuntu 16.04.

在 ubuntu 16.04 上安装 libssl-dev 和 python-dev 对我来说就足够了。