无法在 Python 3.9 上使用 Poetry 安装加密包

bol*_*ino 7 python-cryptography python-poetry

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

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

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

知道为什么以及如何解决这个问题吗?最新的加密模块信息表明它与 Python 3.6+ 兼容

que*_*o42 5

我也遇到了同样的问题,甚至在Cannot \xe2\x80\x9cpip install cryptography\xe2\x80\x9d in Docker Alpine Linux 3.3 with OpenSSL 1.0.2g and Python 2.7 中遵循此答案安装货物以获取 Rust 也不起作用我的案例,尽管它被许多人认可为可行的解决方案。我有一个 alpine docker 容器,我在 Cargo 之后 pip 安装了 Poetry,再次出现相同的错误。\n安装 Cargo 确实安装了 Rust,但在安装密码学期间,Poetry 没有找到它。

\n

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

\n

同一链接的另一个被接受的答案显示了这种方式:

\n

你需要安装

\n
gcc musl-dev python3-dev libffi-dev openssl-dev\n
Run Code Online (Sandbox Code Playgroud)\n

使用 apt、apk 或其他。

\n

然后你就可以 pip install cryptography 了。对于 Python 3.9,您只需先测试它,无需先确定版本。

\n
python3 -m pip install cryptography\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n
python3 -m pip install cryptography==2.3\n
Run Code Online (Sandbox Code Playgroud)\n

之后,我就可以安装诗歌了。再次,从没有版本的情况开始:

\n
python3 -m pip install poetry\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n
python3 -m pip install "poetry==1.1.8"\n
Run Code Online (Sandbox Code Playgroud)\n

从一个完全初学者的角度来看,我的猜测如下。独立安装程序获取自行安装加密所需的工具,因此运行顺利。另一方面,诗歌似乎使用了一组工具,而没有仅为一个包加载所选工具。如果该池在某种程度上不够兼容,安装就会失败,并且不再需要努力获取运行中所需的工具。

\n


fin*_*mer 4

如果您的平台没有可用的版本cryptography,则需要 Rust 来构建新wheel版本。sdistwheel

请参阅: https: //github.com/pyca/cryptography/issues/5771