【问题标题】:Failed to install cryptography package with Poetry on Python 3.9无法在 Python 3.9 上使用 Poetry 安装加密包
【发布时间】:2021-07-03 23:19:41
【问题描述】:

当我尝试在 Python 3.9.0 虚拟环境中使用 Python Poetry 1.1.4 包管理器 (poetry add cryptography) 安装加密模块时,我得到:

    error: can't find Rust compiler
    
    If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.
    
    To update pip, run:
    
        pip install --upgrade pip
    
    and then retry package installation.
    
    If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at https://rustup.rs) is the recommended way to download and update the Rust compiler toolchain.
    
    This package requires Rust >=1.41.0.
    ----------------------------------------
    ERROR: Failed building wheel for cryptography
  Failed to build cryptography
  ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly

虽然我使用的是 pip 21.0.1(最新),但我对 Python 3.8 没有任何问题。

知道为什么以及如何解决这个问题吗?最新的密码学模块信息说it's compatible with Python 3.6+

【问题讨论】:

    标签: python-poetry python-cryptography


    【解决方案1】:

    如果您的平台没有可用的wheel,则较新版本的cryptography 需要Rust 从sdist 构建wheel

    见:https://github.com/pyca/cryptography/issues/5771

    【讨论】:

    • 谢谢。虽然线程说它仍然可以在像 MacOS 这样的二进制轮子的操作系统上工作,但是在我的平台(MacOS)上,它不起作用,所以我还是有点困惑。
    【解决方案2】:

    我遇到了同样的问题,即使在 Cannot “pip install cryptography” in Docker Alpine Linux 3.3 with OpenSSL 1.0.2g and Python 2.7 上安装货物以获取 Rust 的答案在我的情况下也不起作用,尽管它被许多人认可为可行的解决方案。我有一个高山码头集装箱,我在货物之后安装了诗歌,再次出现同样的错误。 安装cargo确实安装了Rust,但是在安装密码学的过程中诗歌没有发现。

    这里诗歌问题的解决方案是在安装诗歌之前自行安装密码学。

    other and accepted answer of the same link 指明了方向:

    你需要安装

    gcc musl-dev python3-dev libffi-dev openssl-dev
    

    使用 apt、apk 等。

    然后您可以 pip 安装密码学。使用 Python 3.9,您只需先在没有版本的情况下进行测试。

    python3 -m pip install cryptography
    

    如果崩溃了,就像 Python 3.6 一样,添加一个选择的版本,一个兼容的版本,这里我选择一个与 3.6 一起使用的旧版本 2.3,看起来:

    python3 -m pip install cryptography==2.3
    

    之后,我可以安装诗歌。同样,从没有版本开始:

    python3 -m pip install poetry
    

    如果失败,请选择一个兼容版本,在我的情况下,我需要一个与 Python 3.6 兼容的旧版本:

    python3 -m pip install "poetry==1.1.8"
    

    从一个初学者的角度来看,我的猜测如下。独立安装程序获得了自行安装密码学所需的工具,因此运行低谷。另一方面,诗歌似乎使用了一个工具池,而不是只为一个包加载选定的工具。如果该池在某种程度上不够兼容,则安装会失败,并且无需再努力在运行中获取所需的工具。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-06
      • 1970-01-01
      • 1970-01-01
      • 2022-10-20
      • 1970-01-01
      • 2021-02-07
      • 2021-09-03
      • 2022-06-30
      相关资源
      最近更新 更多