[英]Failed to install Python Cryptography package with PIP and setup.py
当我尝试通过pip install cryptography
或从他们的站点下载 package 并运行python setup.py
为 Python 安装Cryptography package 时,我收到以下错误:
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 错误帖子( 此处和此处),但那里提供的解决方案无法解决我的问题。 另外,我可以通过 PIP 安装其他包。
PIP 版本 1.5.4 setuptools 版本 2.2
我有一个类似的问题,发现我只是缺少一个依赖项(libssl-dev,对我来说)。 如https://cryptography.io/en/latest/installation/中所述,确保满足所有依赖项:
如果您使用的是 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
如果您有 C 编译器、Python 头文件(如果您不使用 pypy)以及系统上可用的 OpenSSL 和 libffi 库的头文件,那么密码学应该很容易在 Linux 上构建。
对于Debian 和 Ubuntu ,以下命令将确保安装所需的依赖项:
sudo apt-get install build-essential libssl-dev libffi-dev python-dev
对于Fedora 和 RHEL-derivatives ,以下命令将确保安装所需的依赖项:
sudo yum install gcc libffi-devel python-devel OpenSSL-devel
您现在应该能够像往常一样构建和安装密码学了。
pip install cryptography
这是密码学安装文档页面上的信息的精简版本。 有关最新详细信息,请参阅该页面。
由于这个 SO 问题不断出现,我也会在此处回复(我是 pyca/密码学开发人员之一)。 这是在 3 个主要平台上可靠地安装 pyca/cryptography 所需的内容。
请注意,在所有这些情况下,强烈建议您安装到 virtualenv 而不是全局包空间中。 这不是特定于密码学的,而是保持 Python 安装可靠的通用建议。 操作系统提供的 Python 中的全局包空间归系统所有,通过 pip 将东西安装到其中是自找麻烦。
视窗
升级到最新的 pip 并只需pip install cryptography
密码学和 cffi 都作为静态链接轮子提供。
macOS (OS X)
升级到最新的 pip 并只需pip install cryptography
密码学和 cffi 都作为静态链接轮子提供。 这适用于 pyenv Python、system Python、homebrew Python 等。只要你使用最新的 pip,你甚至不需要编译器。
Linux
在基于 glibc 或基于 musl 的发行版和 x86/x86-64/aarch64 上运行最新 pip (升级!)的用户不再需要编译器或头文件,因为您将自动获得预编译轮。 因此,您应该尝试的第一件事是升级您的 pip 并安装最新的加密版本,因为旧版本没有更新的轮子类型。
如果您不兼容 manylinux/musllinux 或希望针对您自己的 OpenSSL 进行编译,那么您需要执行以下操作:
你需要一个 C 编译器、一个Rust 编译器、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
请注意,从 3.4 版开始,密码学现在需要在构建时(而不是在运行时)使用 Rust 编译器,因此您还需要 Rust >= 1.41.0。 检查您的发行版的 rust 或通过 rustup 安装它
对于那些运行 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
这为我解决了这个问题(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
显然,在最新版本的 OSX 上,这可能是由于 Apple 发布了他们自己的 OpenSSL 版本,该版本不适用于密码库。
加密库的最新版本附带了它们自己的本机依赖项,但要获得它们,您需要升级 pip,可能还需要升级虚拟环境。 所以对我来说,解决方案是:
pip install --upgrade --force-reinstall pip virtualenv
我在上面尝试了许多解决方案,但只有在安装了以下库之后,我才能安装cryptography
:
sudo apt install libssl1.0
我使用的是 Ubuntu 18.04,但它也可以在 Ubuntu 18.10 上运行。
UPD:要解决 Ubuntu 20 上的此错误,我必须将cryptography==1.9
替换为cryptography==2.1.1
我如何解决“密码学清理构建目录失败”
(我从谷歌来到这里是为了解决这个错误。)
注意:使用 virtualenv
我的文件/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
hth
这对我有用(我使用的是 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
资料来源:
尼克伍德汉姆的回答对我来说不适用于 OSX 10.11 El Capitan,但确实如此。
brew install openssl
CFLAGS="-I/usr/local/opt/openssl/include" pip install cryptography==0.8
如果您要对 python 应用程序进行 docker 化,您的 Dockerfile 需要具有以下内容:
FROM python:3.7-alpine
RUN apk add --update alpine-sdk && apk add libffi-dev openssl-dev
运行 pip 安装密码学
如果您正在为 GitLab CI 构建一个.gitlab-ci.yml文件中的 python 包分发,该文件使用部署在 AWS EC2 机器中的 gitlab 运行器
- apk add --update alpine-sdk && \
- apk add libffi-dev openssl-dev && \
- apk --no-cache --update add build-base
如果您使用的是 python3,则需要安装python3-dev
。 这解决了我的问题sudo apt-get install python3-dev
。
我在 Ubuntu 16.04 上安装cryptography==1.7.1
时遇到问题,上面的答案都没有帮助。 因此,我将要求升级到兼容的 1.8.2并且设置成功。 请注意,您仍然需要顶部(最受好评的)答案中提到的构建要素和其他依赖项。
我在运行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
我注意到原始海报显然使用的是 Windows 安装......上面的最佳答案都是针对其他操作系统的......所以就这样吧。 这假设您已经安装了 Python 2.7,这是最广泛支持的(虽然是旧的)版本。
重新运行 pip install (package) 例如
cd C:\Python27\Scripts pip install cryptography (or pycrypto, fabric, etc)
这适用于带有 MacPorts 的 El Capitan:
$ sudo port install openssl
$ env LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" pip install cryptography
我最近遇到了类似的问题。 在我的情况下,在 requirements.txt 中编写的cffi
和cryptography
版本不兼容(cffi==1.8.9 和密码学==1.9)。 我解决了用最后一个可用版本更新cffi
的问题。
升级pip版本解决了问题
pip install --upgrade pip
(适用于 mac/linux 发行版)
实际上,我在尝试安装 Scrapy 时遇到了同样的问题,这取决于首先安装的密码学。 我在安装了 Python 2.7 64 位的 Win764 位。 @jsonm 的答案最终对我有用,但首先我必须将C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvarsx86_amd64.bat
x86_amd64
该 bin 目录中的 x86_amd64 子目录,这样vcvarsall.bat
就会停止抛出一个错误,说它缺少配置。 如果您需要为不同的设置配置环境变量,请务必将相应的 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
它奏效了。
我也有这个错误。 即使在安装 openSSL 后继续出现此错误后,我最终尝试从https://pypi.python.org/pypi/cryptography/0.2.2#downloads的轮文件安装。 有效!
我从 pypi 下载了 paramiko 完整的源代码并做了
python setup.py 安装
它完美无缺
所有默认的 pythondev / openssl /libffi 包都已经存在于 rhel 中。
下载 rpm 有 rpm 不匹配,比较麻烦
conda
在Raspbian 10 (buster)
上,没有一个建议的解决方案对我有用,所以我只是通过conda
安装它,瞧:
conda install -c anaconda cryptography
PS :我知道问题提到了pip
,但我看到 OP 正在使用conda
安装,所以我还是想分享这个解决方案。 尽管如此,由于这个问题显然是特定于操作系统的,因此提醒人们conda
是一种跨平台解决方案是有意义的,它还可以安装除python
包之外的必要二进制文件 - 只有一个线。
你必须在运行安装之前升级你的 pip
我有同样的问题:
pip install cryptography
.
.
.
Installing collected packages: cffi, cryptography
Running setup.py install for cffi ... error
然后我安装 libffi-devel 问题就解决了
yum install libffi-devel
这两个命令为我修复了它:
brew install openssl
brew link openssl --force
来源: https ://github.com/phusion/passenger/issues/1630#issuecomment-147527656
我通过从密码学 1.9 升级到 2.4.2 解决了这个问题
在 Cygwin 有同样的问题,这对我有帮助
sudo apt-get install python-pip python-dev libffi-dev libssl-dev libxml2-dev libxslt1-dev libjpeg8-dev zlib1g-dev
但我没有安装 sudo apt-get install,而是通过Cygwin安装了这些包
在 Debian 11(可能还有大多数新的 Linux 发行版)中:
sudo apt install python3-cryptography
python3.7 -m pip install <your package>
对我来说,django-allauth 给出了这个错误。 我解决了它使用
python3.7 -m pip install django-allauth
使用如下命令更新 pip 的版本:
只需选择一个进行更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.