错误:无法为使用 PEP 517 且无法直接安装的加密构建轮子

Chi*_*ali 40 python cryptography pip python-cryptography

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
Run Code Online (Sandbox Code Playgroud)

我已经安装OpenSSL和设置环境变量中所建议的这个帖子却问题依旧。我的设置细节:

  • 系统 - Windows 10
  • 蟒蛇 - 3.8
  • 点子 - 19.3.1

Abh*_*bhi 34

在 requirements.txt 中将加密设置为 2.8 版修复了该问题。

  • 将其设置为 2.9.2 似乎也有效 (2认同)

nav*_*ule 29

TLDR;

尝试使用 cryptography==3.1.1

细节:

这发生Python 3.9.0Windows 10PC上。我在requirements.txt中有以下内容

cryptography==2.8
Run Code Online (Sandbox Code Playgroud)

我删除了这个版本,只在如下的requirements.txt文件中保留了密码学

cryptography
Run Code Online (Sandbox Code Playgroud)

保存了requirements.txt然后我跑了

pip install -r requirements.txt
Run Code Online (Sandbox Code Playgroud)

它安装成功。然后我通过运行以下命令冻结requirements.txt

pip freeze > requirements.txt
Run Code Online (Sandbox Code Playgroud)

然后requirements.txt得到更新cryptography==3.1.1


小智 21

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

sudo apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo
Run Code Online (Sandbox Code Playgroud)

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


Jos*_*osé 21

在我的情况下(Windows 10 + conda)更新 pip 解决了这个问题:

python -m pip install --upgrade pip
Run Code Online (Sandbox Code Playgroud)


Tus*_*ave 19

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

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


小智 8

您可以使用最新版本

python3 -m pip install --no-use-pep517 cryptography
Run Code Online (Sandbox Code Playgroud)

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

  • 错误:禁用 PEP 517 处理无效:项目在 pyproject.toml 中指定了 setuptools.build_meta 的构建后端 (3认同)

小智 8

pip install --upgrade pip
Run Code Online (Sandbox Code Playgroud)

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


Ane*_*way 7

碰到这个问题,解决方法其实就在pip尝试在加密前安装openssl时的消息中:

  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=============================
Run Code Online (Sandbox Code Playgroud)

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

pip install -U pip
Run Code Online (Sandbox Code Playgroud)

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