當前位置: 首頁>>技術教程>>正文


python – 如何在ubuntu上安裝加密技術?

, , ,

問題描述

我的Ubuntu版本是14.04 LTS。

當我安裝密碼術時,錯誤是:

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

我不知道為什麽失敗了。是什麽原因。在ubuntu係統上安裝時是否有必要?

最佳思路

答案在cryptographyinstallation section的文檔上,這幾乎反映了Angelos的答案:

引用:

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 

如果您使用的是Python 3,請在第一個命令中使用python3-dev而不是python-dev。 (感謝@chasmani)

如果要在Ubuntu 18.04上安裝此軟件,請在第一個命令中使用libssl1.0代替libssl-dev。 (感謝@pobe)

次佳思路

當在Ubuntu 14.04上安裝加密模塊時,我遇到了同樣的問題。我通過安裝libffi-dev解決了這個問題:

apt-get install -y libffi-dev

然後我得到以下錯誤:

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

我通過安裝libssl-dev解決了該問題:

apt-get install -y libssl-dev

參考資料

本文由Ubuntu問答整理, 博文地址: https://ubuntuqa.com/zh-tw/article/9037.html,未經允許,請勿轉載。