7

When I try to install cryptography module with Python Poetry 1.1.4 package manager (poetry add cryptography) in a Python 3.9.0 virtual environment, I get:

    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

Though I'm using pip 21.0.1 (latest), and I have no issue with Python 3.8.

Any idea on why and how to solve that? Latest cryptography module information says it's compatible with Python 3.6+.

bolino
  • 867
  • 1
  • 10
  • 27

2 Answers2

5

I had the same issue, and even following this answer at Cannot “pip install cryptography” in Docker Alpine Linux 3.3 with OpenSSL 1.0.2g and Python 2.7 of installing cargo to get Rust did not work in my case, though it was approved by many as a working solution. I have an alpine docker container where I pip installed poetry after cargo, with the same error again. Installing cargo does indeed install Rust, but it is not found by poetry during installation of cryptography.

The solution for this poetry problem here is to install cryptography on its own before you install poetry.

The other and accepted answer of the same link shows the way:

You need to install

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

using apt, apk or whatever.

Then you can pip install cryptography. With Python 3.9, you just test this without a version first.

python3 -m pip install cryptography

If that crashes, as it does with Python 3.6, add a chosen version, one that is compatible, here I take an old version 2.3 that works with 3.6, it seems:

python3 -m pip install cryptography==2.3

After this, I could install poetry. Again, start without a version:

python3 -m pip install poetry

And if that fails, choose a compatible version, in my case I needed an older one compatible with Python 3.6:

python3 -m pip install "poetry==1.1.8"

From a total beginner's perspective, my guess is as follows. The standalone installer gets the tools needed to get cryptography installed on its own and therefore runs trough. On the other hand, poetry seems to use a pool of tools without loading chosen tools only for one package. And if that pool is somehow not compatible enough, the installation fails and there is no more effort to reach out for the needed tools on the run.

questionto42
  • 7,175
  • 4
  • 57
  • 90
4

Newer version of cryptography requires Rust to build a wheel from sdist if no wheel is available for your platform.

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

finswimmer
  • 10,896
  • 3
  • 34
  • 44
  • 1
    Thanks. Although the thread says it still works on OS with binary wheels like MacOS, but on my platform (MacOS), it doesn't work, so it's still a bit confusing to me. – bolino Apr 09 '21 at 07:40