【问题标题】:ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly错误:无法为使用 PEP 517 且无法直接安装的密码学构建轮子
【发布时间】:2020-04-13 22:39:17
【问题描述】:

当 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
  • 点 - 19.3.1

【问题讨论】:

  • 在 Windows 上构建加密是一个非常复杂的过程,除非您尝试安装较旧的加密版本,否则不需要它。密码学为密码学 2.8+ 提供 Python 3.8 windows 轮子。如果你直接运行pip install cryptography 会发生什么?
  • 直接安装就可以了。但是,当我将它作为 requirements.txt 的一部分安装时,会显示此错误。我应该如何禁用构建轮子的选项?如果我这样做会有什么后果?
  • 在我的情况下,有必要将 pip 更新到最新版本
  • @dreo 我已经更新了 Pip 但它仍然为包构建轮子
  • requirements.txt 是否将加密固定到版本

标签: python pip cryptography python-cryptography


【解决方案1】:

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

pip install cryptography==3.1.1

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

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

python -m pip install --upgrade pip

sudo pip install -U pip setuptools

【讨论】:

    【解决方案2】:

    也有这个问题。如果您使用的是 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

    【讨论】:

      【解决方案3】:

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

      python -m pip install --upgrade pip
      

      【讨论】:

      【解决方案4】:
      pip install --upgrade pip
      

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

      【讨论】:

        【解决方案5】:

        我有同样的问题。 pip3 版本是 19.* 升级后它可以工作

        sudo -H pip3 install --upgrade pip
        

        【讨论】:

          【解决方案6】:

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

          【讨论】:

            【解决方案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=============================
            

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

            pip install -U pip
            

            将 pip 从 18.0 版更新到 21.0.1 版

            【讨论】:

              【解决方案8】:

              您可以使用最新版本

              python3 -m pip install --no-use-pep517 cryptography
              

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

              【讨论】:

              • 错误:禁用 PEP 517 处理无效:项目在 pyproject.toml 中指定 setuptools.build_meta 的构建后端
              【解决方案9】:

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

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

              【讨论】:

              • 这对我有用,但我还必须升级我的 tox 目录中的 pip 以启用 tox 来设置我的依赖项。作为参考,我使用的是 OSX Big Sur,python 3.8,并将两个点从 20.3.3 升级到 21.0。
              【解决方案10】:

              TLDR;

              尝试使用cryptography==3.1.1

              详情:

              这发生在Python 3.9.0Windows 10 PC 上。 我在 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

              【讨论】:

              • 我收到以下错误:错误:构建加密轮失败 无法构建加密错误:无法构建使用 PEP 517 且无法直接安装的加密轮
              • 你按照上面提到的方法了吗?
              • 是的@navule,我遵循了所有步骤。
              • 他们在 v3.4 中开始使用 Rust,所以为了避免 Rust,您可以使用的最新版本是 cryptography==3.3.2
              • @Igor Jerosimić thx 伙计,这是唯一有意义且真正有帮助的答案。 Navule 只是随机更改版本,没有任何类型的扩展。
              【解决方案11】:

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

              【讨论】:

              • 为我工作。我在设置 ESP Rainmaker(CLI 设置)时遇到了这个问题
              【解决方案12】:

              我尝试在 Windows 10 上使用 Python 3.8.1 安装 Scrapy 时遇到此错误,但它解决了安装 pip 的最新版本(在我的情况下为 19.3.1),并且所有使用 pip 的方法都是这样:

              python -m pip install scrapy --user
              

              【讨论】:

              • 谢谢。这也对我有用。我的系统是 Windows 10、Python 3.8.2、Pycharm,并且 netmiko 没有从 Pycharm 的 requirements.txt 文件中安装。我进入了 venv,然后运行 ​​pip install cryptography ,它也不起作用。然后我尝试了 python -m pip install cryptography ,它安装没有任何问题。之后回到Pycharm需求文件,点击netmiko入口安装,运行顺利。
              猜你喜欢
              • 2020-11-01
              • 2021-04-14
              • 2020-08-05
              • 2021-02-28
              • 2020-10-16
              • 1970-01-01
              • 1970-01-01
              • 2021-03-07
              • 2021-06-22
              相关资源
              最近更新 更多