在 Raspberry Pi 2B (armv7h Arch Linux ARM) (python 3.9.8) 上安装加密问题

Issue installing cryptography on Raspberry Pi 2B (armv7h Arch Linux ARM) (python 3.9.8)

我在 raspberry pi 上安装 python cryptography 包时遇到一些问题,特别是 python 版本 3.9.8(与 pyenv 一起安装)。 cryptography 包是使用 pacman(python-cryptography 包)安装在我的系统上的,因此可以使用主 python 解释器 (3.10.1)。但是,我需要一些版本的 python 3.9 专门用于我在这个项目中使用的另一个包。每当我尝试通过 python 3.9.8 环境安装 cryptography 时,我都会收到以下错误:

Building wheels for collected packages: cryptography
  Building wheel for cryptography (pyproject.toml): started
  Building wheel for cryptography (pyproject.toml): finished with status 'error'
Failed to build cryptography

  ERROR: Command errored out with exit status 1:
   command: /home/kioskuser/.local/share/virtualenvs/Kivy-Raspi-Desktop-App-EzpaxvF4/bin/python /home/kioskuser/.local/share/virtualenvs/Kivy-Raspi-Desktop-App-EzpaxvF4/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmp4zxk3vu2
       cwd: /tmp/pip-install-c5oajf7r/cryptography_5c58967b948d4a78862f30763d6e3c9e
  Complete output (163 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-armv7l-3.9
  creating build/lib.linux-armv7l-3.9/cryptography
  copying src/cryptography/utils.py -> build/lib.linux-armv7l-3.9/cryptography
  copying src/cryptography/fernet.py -> build/lib.linux-armv7l-3.9/cryptography
  copying src/cryptography/exceptions.py -> build/lib.linux-armv7l-3.9/cryptography
  copying src/cryptography/__init__.py -> build/lib.linux-armv7l-3.9/cryptography
  copying src/cryptography/__about__.py -> build/lib.linux-armv7l-3.9/cryptography
  creating build/lib.linux-armv7l-3.9/cryptography/x509
  copying src/cryptography/x509/oid.py -> build/lib.linux-armv7l-3.9/cryptography/x509
  copying src/cryptography/x509/ocsp.py -> build/lib.linux-armv7l-3.9/cryptography/x509
  copying src/cryptography/x509/name.py -> build/lib.linux-armv7l-3.9/cryptography/x509
  copying src/cryptography/x509/general_name.py -> build/lib.linux-armv7l-3.9/cryptography/x509
  copying src/cryptography/x509/extensions.py -> build/lib.linux-armv7l-3.9/cryptography/x509
  copying src/cryptography/x509/certificate_transparency.py -> build/lib.linux-armv7l-3.9/cryptography/x509
  copying src/cryptography/x509/base.py -> build/lib.linux-armv7l-3.9/cryptography/x509
  copying src/cryptography/x509/__init__.py -> build/lib.linux-armv7l-3.9/cryptography/x509
  creating build/lib.linux-armv7l-3.9/cryptography/hazmat
  copying src/cryptography/hazmat/_oid.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat
  copying src/cryptography/hazmat/__init__.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat
  creating build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/poly1305.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/padding.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/keywrap.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/hmac.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/hashes.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/constant_time.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/cmac.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/_serialization.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/_cipheralgorithm.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/_asymmetric.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/__init__.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives
  creating build/lib.linux-armv7l-3.9/cryptography/hazmat/bindings
  copying src/cryptography/hazmat/bindings/__init__.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/bindings
  creating build/lib.linux-armv7l-3.9/cryptography/hazmat/backends
  copying src/cryptography/hazmat/backends/interfaces.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends
  copying src/cryptography/hazmat/backends/__init__.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends
  creating build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/twofactor
  copying src/cryptography/hazmat/primitives/twofactor/totp.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/twofactor
  copying src/cryptography/hazmat/primitives/twofactor/hotp.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/twofactor
  copying src/cryptography/hazmat/primitives/twofactor/__init__.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/twofactor
  creating build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/serialization
  copying src/cryptography/hazmat/primitives/serialization/ssh.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/serialization
  copying src/cryptography/hazmat/primitives/serialization/pkcs7.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/serialization
  copying src/cryptography/hazmat/primitives/serialization/pkcs12.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/serialization
  copying src/cryptography/hazmat/primitives/serialization/base.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/serialization
  copying src/cryptography/hazmat/primitives/serialization/__init__.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/serialization
  creating build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/kdf
  copying src/cryptography/hazmat/primitives/kdf/x963kdf.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/kdf
  copying src/cryptography/hazmat/primitives/kdf/scrypt.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/kdf
  copying src/cryptography/hazmat/primitives/kdf/pbkdf2.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/kdf
  copying src/cryptography/hazmat/primitives/kdf/kbkdf.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/kdf
  copying src/cryptography/hazmat/primitives/kdf/hkdf.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/kdf
  copying src/cryptography/hazmat/primitives/kdf/concatkdf.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/kdf
  copying src/cryptography/hazmat/primitives/kdf/__init__.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/kdf
  creating build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/ciphers
  copying src/cryptography/hazmat/primitives/ciphers/modes.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/ciphers
  copying src/cryptography/hazmat/primitives/ciphers/base.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/ciphers
  copying src/cryptography/hazmat/primitives/ciphers/algorithms.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/ciphers
  copying src/cryptography/hazmat/primitives/ciphers/aead.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/ciphers
  copying src/cryptography/hazmat/primitives/ciphers/__init__.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/ciphers
  creating build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/x448.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/x25519.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/utils.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/types.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/rsa.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/padding.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/ed448.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/ed25519.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/ec.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/dsa.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/dh.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/__init__.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/primitives/asymmetric
  creating build/lib.linux-armv7l-3.9/cryptography/hazmat/bindings/openssl
  copying src/cryptography/hazmat/bindings/openssl/binding.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/bindings/openssl
  copying src/cryptography/hazmat/bindings/openssl/_conditional.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/bindings/openssl
  copying src/cryptography/hazmat/bindings/openssl/__init__.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/bindings/openssl
  creating build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/x509.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/x448.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/x25519.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/utils.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/rsa.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/poly1305.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/hmac.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/hashes.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/encode_asn1.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/ed448.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/ed25519.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/ec.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/dsa.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/dh.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/decode_asn1.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/cmac.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/ciphers.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/backend.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/aead.py -> build/lib.linux-armv7l-3.9/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/__init__.py -> build/lib.linux-armv7l-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-armv7l-3.9/cryptography
  creating build/lib.linux-armv7l-3.9/cryptography/hazmat/bindings/_rust
  copying src/cryptography/hazmat/bindings/_rust/__init__.pyi -> build/lib.linux-armv7l-3.9/cryptography/hazmat/bindings/_rust
  copying src/cryptography/hazmat/bindings/_rust/asn1.pyi -> build/lib.linux-armv7l-3.9/cryptography/hazmat/bindings/_rust
  copying src/cryptography/hazmat/bindings/_rust/ocsp.pyi -> build/lib.linux-armv7l-3.9/cryptography/hazmat/bindings/_rust
  copying src/cryptography/hazmat/bindings/_rust/x509.pyi -> build/lib.linux-armv7l-3.9/cryptography/hazmat/bindings/_rust
  warning: build_py: byte-compiling is disabled, skipping.
  
  running build_ext
  cargo rustc --lib --manifest-path src/rust/Cargo.toml --release -v --features pyo3/abi3-py36 pyo3/extension-module -- --crate-type cdylib
     Compiling proc-macro2 v1.0.32
     Compiling unicode-xid v0.2.2
     Compiling syn v1.0.81
     Compiling autocfg v1.0.1
       Running `rustc --crate-name build_script_build --edition=2018 /home/kioskuser/.cargo/registry/src/github.com-1285ae84e5963aae/proc-macro2-1.0.32/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off -C overflow-checks=on --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=7a95d32b66ae1a1f -C extra-filename=-7a95d32b66ae1a1f --out-dir /tmp/pip-install-c5oajf7r/cryptography_5c58967b948d4a78862f30763d6e3c9e/src/rust/target/release/build/proc-macro2-7a95d32b66ae1a1f -L dependency=/tmp/pip-install-c5oajf7r/cryptography_5c58967b948d4a78862f30763d6e3c9e/src/rust/target/release/deps --cap-lints allow`
       Running `rustc --crate-name unicode_xid /home/kioskuser/.cargo/registry/src/github.com-1285ae84e5963aae/unicode-xid-0.2.2/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debug-assertions=off -C overflow-checks=on --cfg 'feature="default"' -C metadata=2b7724452eebc032 -C extra-filename=-2b7724452eebc032 --out-dir /tmp/pip-install-c5oajf7r/cryptography_5c58967b948d4a78862f30763d6e3c9e/src/rust/target/release/deps -L dependency=/tmp/pip-install-c5oajf7r/cryptography_5c58967b948d4a78862f30763d6e3c9e/src/rust/target/release/deps --cap-lints allow`
       Running `rustc --crate-name build_script_build --edition=2018 /home/kioskuser/.cargo/registry/src/github.com-1285ae84e5963aae/syn-1.0.81/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off -C overflow-checks=on --cfg 'feature="clone-impls"' --cfg 'feature="default"' --cfg 'feature="derive"' --cfg 'feature="extra-traits"' --cfg 'feature="full"' --cfg 'feature="parsing"' --cfg 'feature="printing"' --cfg 'feature="proc-macro"' --cfg 'feature="quote"' -C metadata=6954389b44e215f9 -C extra-filename=-6954389b44e215f9 --out-dir /tmp/pip-install-c5oajf7r/cryptography_5c58967b948d4a78862f30763d6e3c9e/src/rust/target/release/build/syn-6954389b44e215f9 -L dependency=/tmp/pip-install-c5oajf7r/cryptography_5c58967b948d4a78862f30763d6e3c9e/src/rust/target/release/deps --cap-lints allow`
       Running `rustc --crate-name autocfg /home/kioskuser/.cargo/registry/src/github.com-1285ae84e5963aae/autocfg-1.0.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debug-assertions=off -C overflow-checks=on -C metadata=062cd71dd028816e -C extra-filename=-062cd71dd028816e --out-dir /tmp/pip-install-c5oajf7r/cryptography_5c58967b948d4a78862f30763d6e3c9e/src/rust/target/release/deps -L dependency=/tmp/pip-install-c5oajf7r/cryptography_5c58967b948d4a78862f30763d6e3c9e/src/rust/target/release/deps --cap-lints allow`
  error: could not compile `unicode-xid`
  
  Caused by:
    process didn't exit successfully: `rustc --crate-name unicode_xid /home/kioskuser/.cargo/registry/src/github.com-1285ae84e5963aae/unicode-xid-0.2.2/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debug-assertions=off -C overflow-checks=on --cfg 'feature="default"' -C metadata=2b7724452eebc032 -C extra-filename=-2b7724452eebc032 --out-dir /tmp/pip-install-c5oajf7r/cryptography_5c58967b948d4a78862f30763d6e3c9e/src/rust/target/release/deps -L dependency=/tmp/pip-install-c5oajf7r/cryptography_5c58967b948d4a78862f30763d6e3c9e/src/rust/target/release/deps --cap-lints allow` (signal: 4, SIGILL: illegal instruction)
  warning: build failed, waiting for other jobs to finish...
  error: build failed
  
      =============================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.8
      platform: Linux-5.10.90-1-rpi-ARCH-armv7l-with-glibc2.32
      pip: n/a
      setuptools: 60.5.0
      setuptools_rust: 1.1.2
      =============================DEBUG ASSISTANCE=============================
  
  error: cargo failed with code: 101
  
  ----------------------------------------
  ERROR: Failed building wheel for cryptography
ERROR: Could not build wheels for cryptography, which is required to install pyproject.toml-based projects

✘ Installation Failed

到目前为止我已经尝试过:

  1. 正在升级 pip(现在是 21.3.1 版)
  2. 确保安装了 rust 编译器(rustc 版本 1.57.0)
  3. 确保 libffi 已安装(版本 3.4.2)
  4. 确保 OpenSSL 已安装(版本 1.1.1)
  5. 作为 Arch Linux 系统,我当然 gcc 安装了 C 编译器(版本 10.2.0)
  6. 将问题隔离到这个包(我最初试图安装 cryptography 作为 msal 的依赖项)
  7. 尝试使用 pipenv 以及直接导航到 ~/.pyenv/versions/3.9.8 目录中的 python 可执行文件
  8. ~/.pyenv/versions/3.9.8 目录中,尝试使用 pip 可执行文件以及 ./python -m pip 进行安装,两次结果相同。
  9. 上述步骤还包括检查错误消息中建议的所有 4 个调试步骤。

注意所有这些在我的主系统(也是 Arch Linux,但 x86_64 而不是 ARM)的虚拟环境中完美运行可能也很有用。

我还可以尝试安装 cryptography 软件包吗?

或者,似乎通过 pacman 在主站点包中安装了相同版本的库,但是虚拟环境或单独版本的 [=60] 当然无法识别=].有什么方法可以强制 python 3.9.8 使用那个包吗?

@jakub 的解决方案最终为我解决了问题。我卸载了通过 pacman 安装的 rust 版本。为了替换它,我安装了 rustup,然后使用 rustup,安装了最新的 rust 每晚版本 (1.60)。一旦我这样做了,安装 cryptography 包就可以正常工作了。

如果您正在使用 rustup,只需确保在 安装之前将 ~/.cargo/bin 添加到 PATH 。另外,我用来通过 rustup 安装 rust 的命令是 rustup toolchain install nightly.