ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly

ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly

当 pip 为加密包构建轮子时出现错误。

错误:

LINK : fatal error LNK1181: cannot open input file 'libssl.lib'
  error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\link.exe' failed with exit status 1181
  ----------------------------------------
  ERROR: Failed building wheel for cryptography
  Running setup.py clean for cryptography
Failed to build cryptography
ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly

我已经安装了 OpenSSL 并按照 this post 中的建议设置了环境变量,但问题仍然存在。我的设置详情:

我在 Windows 10 上尝试使用 Python 3.8.1 安装 Scrapy 时遇到此错误,但它解决了安装最新版本的 pip(在我的例子中是 19.3.1)并且一切正常以这种方式使用 pip:

python -m pip install scrapy --user

在 requirements.txt 中将加密设置为版本 2.8 解决了这个问题。

TLDR;

尝试使用 cryptography==3.1.1

详情:

这发生在 Windows 10 PC 上的 Python 3.9.0 上。 我在 requirements.txt

中有以下内容
cryptography==2.8

我删除了版本,只在 requirements.txt 文件中保留了密码,如下所示

cryptography

保存了requirements.txt然后我运行

pip install -r requirements.txt

安装成功。 然后我通过 运行 以下命令

冻结 requirements.txt
pip freeze > requirements.txt

然后 requirements.txt 更新为 cryptography==3.1.1

我遇到了同样的问题,并尝试按照上述步骤安装 openssl,但仍然无法继续 windows 10。后来我将 pip 升级到最新版本并再次尝试,它没有任何问题。

我建议将 pip 升级到最新版本并在继续安装 openssl 之前尝试一下

您可以将最新版本与

一起使用
python3 -m pip install --no-use-pep517 cryptography

在 arm32v7 上使用 ubuntu:18.04 为我工作 (而不是按照错误消息的建议安装完整的 rust 编译器和 build-essentials,或者升级 pip(对我的 armbian 上的 ubuntu:18.04 没有影响))

运行进入这个问题,解决方法其实在pip尝试安装openssl before cryptography时的消息中:

  generating cffi module 'build/temp.linux-x86_64-3.7/_openssl.c'
  running build_rust
  
      =============================DEBUG ASSISTANCE=============================
      If you are seeing a compilation error please try the following steps to
      successfully install cryptography:
      1) Upgrade to the latest pip and try again. This will fix errors for most
         users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
      2) Read https://cryptography.io/en/latest/installation.html for specific
         instructions for your platform.
      3) Check our frequently asked questions for more information:
         https://cryptography.io/en/latest/faq.html
      4) Ensure you have a recent Rust toolchain installed:
         https://cryptography.io/en/latest/installation.html#rust
      5) If you are experiencing issues with Rust for *this release only* you may
         set the environment variable `CRYPTOGRAPHY_DONT_BUILD_RUST=1`.
      =============================DEBUG ASSISTANCE=============================

只是 运行 pip update 命令似乎对我有用:

pip install -U pip

哪个更新了 pip 从版本 18.0 到版本 21.0.1

也有这个问题。如果您使用的是 alpine,请确保安装了所有加密依赖项。 在我的例子中,货物包裹丢失并导致了问题。

sudo apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo

https://cryptography.io/en/latest/installation.html#building-cryptography-on-linux

就我而言 (windows 10 + conda) 更新 pip 解决了问题:

python -m pip install --upgrade pip

我遇到了这个问题,我刚刚安装了 Rust 并为我解决了问题 您可以在安装 rust 编程语言后安装最终版本的密码学(不要尝试 pip install rust,它不是 python 包) https://www.rust-lang.org/tools/install

我遇到了同样的问题。 pip3 版本为 19.* 升级后有效

sudo -H pip3 install --upgrade pip
pip install --upgrade pip

尝试升级对我来说工作正常的环境的 pip。

您可以尝试安装cryptography==3.1.1包,而不是cryptography 35版本。

pip install cryptography==3.1.1

如果您仍然面临密码学包集成方面的挑战。

您可以通过以下步骤解决。

python -m pip install --upgrade pip

sudo pip install -U pip setuptools

我在 macOS Monterey(版本 12.2.1)Apple M1 Pro 上遇到过这个问题。我遵循了 Cryptography installation 文档,它帮助我解决了问题。

brew install openssl@1.1 rust

env CRYPTOGRAPHY_SUPPRESS_LINK_FLAGS=1 LDFLAGS="$(brew --prefix openssl@1.1)/lib/libssl.a $(brew --prefix openssl@1.1)/lib/libcrypto.a" CFLAGS="-I$(brew --prefix openssl@1.1)/include" pip3 install cryptography