ERROR: Failed building wheel for cryptography (While moving Home Assistant from Python 3.8 to 3.9)

Building wheel for cryptography (pyproject.toml) … error
ERROR: Command errored out with exit status 1:
command: /srv/homeassistant/bin/python3 /srv/homeassistant/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmp08vsr7oa
cwd: /tmp/pip-install-ea71tq1k/cryptography_a85612093637424897808484e27d0127
Complete output (158 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.9
creating build/lib.linux-x86_64-3.9/cryptography
copying src/cryptography/utils.py β†’ build/lib.linux-x86_64-3.9/cryptography
copying src/cryptography/about.py β†’ build/lib.linux-x86_64-3.9/cryptography
copying src/cryptography/init.py β†’ build/lib.linux-x86_64-3.9/cryptography
copying src/cryptography/fernet.py β†’ build/lib.linux-x86_64-3.9/cryptography
copying src/cryptography/exceptions.py β†’ build/lib.linux-x86_64-3.9/cryptography
creating build/lib.linux-x86_64-3.9/cryptography/hazmat
copying src/cryptography/hazmat/init.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat
copying src/cryptography/hazmat/_oid.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat
creating build/lib.linux-x86_64-3.9/cryptography/x509
copying src/cryptography/x509/general_name.py β†’ build/lib.linux-x86_64-3.9/cryptography/x509
copying src/cryptography/x509/init.py β†’ build/lib.linux-x86_64-3.9/cryptography/x509
copying src/cryptography/x509/oid.py β†’ build/lib.linux-x86_64-3.9/cryptography/x509
copying src/cryptography/x509/ocsp.py β†’ build/lib.linux-x86_64-3.9/cryptography/x509
copying src/cryptography/x509/extensions.py β†’ build/lib.linux-x86_64-3.9/cryptography/x509
copying src/cryptography/x509/name.py β†’ build/lib.linux-x86_64-3.9/cryptography/x509
copying src/cryptography/x509/certificate_transparency.py β†’ build/lib.linux-x86_64-3.9/cryptography/x509
copying src/cryptography/x509/base.py β†’ build/lib.linux-x86_64-3.9/cryptography/x509
creating build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/_asymmetric.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/hmac.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/init.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/_serialization.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/poly1305.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/_cipheralgorithm.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/cmac.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/keywrap.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/hashes.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/constant_time.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/padding.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives
creating build/lib.linux-x86_64-3.9/cryptography/hazmat/bindings
copying src/cryptography/hazmat/bindings/init.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/bindings
creating build/lib.linux-x86_64-3.9/cryptography/hazmat/backends
copying src/cryptography/hazmat/backends/init.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends
copying src/cryptography/hazmat/backends/interfaces.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends
creating build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/twofactor
copying src/cryptography/hazmat/primitives/twofactor/init.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/twofactor
copying src/cryptography/hazmat/primitives/twofactor/hotp.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/twofactor
copying src/cryptography/hazmat/primitives/twofactor/totp.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/twofactor
creating build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/ciphers
copying src/cryptography/hazmat/primitives/ciphers/algorithms.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/ciphers
copying src/cryptography/hazmat/primitives/ciphers/aead.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/ciphers
copying src/cryptography/hazmat/primitives/ciphers/init.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/ciphers
copying src/cryptography/hazmat/primitives/ciphers/modes.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/ciphers
copying src/cryptography/hazmat/primitives/ciphers/base.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/ciphers
creating build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/serialization
copying src/cryptography/hazmat/primitives/serialization/init.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/serialization
copying src/cryptography/hazmat/primitives/serialization/pkcs12.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/serialization
copying src/cryptography/hazmat/primitives/serialization/ssh.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/serialization
copying src/cryptography/hazmat/primitives/serialization/pkcs7.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/serialization
copying src/cryptography/hazmat/primitives/serialization/base.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/serialization
creating build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/kdf
copying src/cryptography/hazmat/primitives/kdf/hkdf.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/kdf
copying src/cryptography/hazmat/primitives/kdf/x963kdf.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/kdf
copying src/cryptography/hazmat/primitives/kdf/init.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/kdf
copying src/cryptography/hazmat/primitives/kdf/kbkdf.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/kdf
copying src/cryptography/hazmat/primitives/kdf/scrypt.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/kdf
copying src/cryptography/hazmat/primitives/kdf/pbkdf2.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/kdf
copying src/cryptography/hazmat/primitives/kdf/concatkdf.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/kdf
creating build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/x25519.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/dh.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/rsa.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/utils.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/init.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/types.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/dsa.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/ed448.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/ec.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/padding.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/x448.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/ed25519.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/primitives/asymmetric
creating build/lib.linux-x86_64-3.9/cryptography/hazmat/bindings/openssl
copying src/cryptography/hazmat/bindings/openssl/init.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/bindings/openssl
copying src/cryptography/hazmat/bindings/openssl/binding.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/bindings/openssl
copying src/cryptography/hazmat/bindings/openssl/_conditional.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/bindings/openssl
creating build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/x25519.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/dh.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/decode_asn1.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/rsa.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/aead.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/backend.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/hmac.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/utils.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/init.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/poly1305.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/cmac.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/ciphers.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/hashes.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/dsa.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/ed448.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/encode_asn1.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/ec.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/x509.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/x448.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/ed25519.py β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/backends/openssl
running egg_info
no previously-included directories found matching β€˜docs/_build’
warning: no previously-included files found matching β€˜vectors’
warning: no previously-included files matching β€˜β€™ found under directory β€˜vectors’
warning: no previously-included files matching '
’ found under directory β€˜.github’
warning: no previously-included files found matching β€˜release.py’
warning: no previously-included files found matching β€˜.coveragerc’
warning: no previously-included files found matching β€˜codecov.yml’
warning: no previously-included files found matching β€˜.readthedocs.yml’
warning: no previously-included files found matching β€˜dev-requirements.txt’
warning: no previously-included files found matching β€˜tox.ini’
warning: no previously-included files found matching β€˜mypy.ini’
warning: no previously-included files matching β€˜β€™ found under directory β€˜.zuul.d’
warning: no previously-included files matching '
’ found under directory β€˜.zuul.playbooks’
writing manifest file β€˜src/cryptography.egg-info/SOURCES.txt’
copying src/cryptography/py.typed β†’ build/lib.linux-x86_64-3.9/cryptography
creating build/lib.linux-x86_64-3.9/cryptography/hazmat/bindings/_rust
copying src/cryptography/hazmat/bindings/_rust/init.pyi β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/bindings/_rust
copying src/cryptography/hazmat/bindings/_rust/asn1.pyi β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/bindings/_rust
copying src/cryptography/hazmat/bindings/_rust/ocsp.pyi β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/bindings/_rust
copying src/cryptography/hazmat/bindings/_rust/x509.pyi β†’ build/lib.linux-x86_64-3.9/cryptography/hazmat/bindings/_rust
running build_ext
error: command failed: β€˜rustc’: No such file or directory (os error 2)

  =============================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/ for specific
     instructions for your platform.
  3) Check our frequently asked questions for more information:
     https://cryptography.io/en/latest/faq/
  4) Ensure you have a recent Rust toolchain installed:
     https://cryptography.io/en/latest/installation/#rust

  Python: 3.9.9
  platform: Linux-4.19.0-8-amd64-x86_64-with-glibc2.28
  pip: n/a
  setuptools: 60.0.4
  setuptools_rust: 1.1.2
  =============================DEBUG ASSISTANCE=============================

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 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 is required to install pyproject.toml-based projects

I followed this guide(Raspberry Pi - Home Assistant) to install Home Assistant over a year ago. The last time I updated Home Assistant was in June. When moving to the next major version of Python(3.9.9) I followed this guide(Home Assistant: upgrade to Python 3.8 - iotechonline) just like earlier this year. It worked fine last time but now I am having the errors listed above and can’t fix them. I troubleshooted for a few hours and tried the commands below but am still where I started. Please let me know how I can fix this and if you need anymore info about the problem.

I have tried running the following commands and they don’t seem to fix it:
pip install --upgrade pip
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
sudo apt install cargo
export CRYPTOGRAPHY_DONT_BUILD_RUST=1
sudo apt remove rustc
sudo apt -y install rustc

1 Like

You’re installing a recent rust, then override it with an old one.

just do

sudo apt remove rustc
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

The curl + sh version does not install a package.

Ok, thank you!

I could solve this problem by installing the latest cryptography piwheel that was sucesfully pre-built, which was 40.0.1 at the time of writing. See www.piwheels.org/project/cryptography/

pip install --force-reinstall -v "cryptography==40.0.1"