Python cryptography がインストールできなくなったら rustup で rust をインストールする

投稿者: ytyng 3年, 2ヶ月 前

Alpine の Dockerfile 内の Pipenv install が失敗する。

cryptography 3.4.1 のインストールで、 ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly で失敗している。

試しに、pipenv ではなく、

pip install cryptography してみると

#10 32.68 [pipenv.exceptions.InstallError]: Collecting cryptography>=1.4
#10 32.68 [pipenv.exceptions.InstallError]: Using cached cryptography-3.4.4.tar.gz (545 kB)
#10 32.68 [pipenv.exceptions.InstallError]: ERROR: Disabling PEP 517 processing is invalid: project specifies a build backend of setuptools.build_meta in pyproject.toml
 generating cffi module 'build/temp.linux-x86_64-3.8/_padding.c'
creating build/temp.linux-x86_64-3.8
generating cffi module 'build/temp.linux-x86_64-3.8/_openssl.c'
running build_rust

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

error: Can not find Rust compiler
----------------------------------------
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
/ #

Rust が必要とのこと。

現在のバージョンは cryptography 3.4.1 、Rust でビルドするようになった。

FAQを見てみると

https://cryptography.io/en/latest/faq.html

今回のバージョンに限り、CRYPTOGRAPHY_DONT_BUILD_RUST の環境変数で、Rust を使わないでビルドできるらしい。

これは最終手段としよう。

試しに rust, cargo をインストールしてやってみる

apk add rust cargo

して、

pip install cryptography

 Running `rustc --crate-name parking_lot_core --edition=2018 /root/.cargo/registry/src/github.com-1ecc6299db9ec823/parking_lot_core-0.8.2/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C metadata=eee97183f997b675 -C extra-filename=-eee97183f997b675 --out-dir /tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps -L dependency=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps --extern cfg_if=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/libcfg_if-cac6a3fe3e67c31f.rmeta --extern instant=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/libinstant-8d8e286f6640e0bb.rmeta --extern libc=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/liblibc-7eee26158fb5ebc8.rmeta --extern smallvec=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/libsmallvec-4a190f9a26ad8e9a.rmeta --cap-lints allow -C target-feature=-crt-static`
Running `rustc --crate-name syn --edition=2018 /root/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-1.0.60/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 --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=e836c33ca097f1fb -C extra-filename=-e836c33ca097f1fb --out-dir /tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps -L dependency=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps --extern proc_macro2=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/libproc_macro2-aa3871282eef8eab.rmeta --extern quote=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/libquote-4a1344d16195b0c6.rmeta --extern unicode_xid=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/libunicode_xid-13530667aae58aae.rmeta --cap-lints allow -C target-feature=-crt-static --cfg syn_disable_nightly_tests`
Compiling parking_lot v0.11.1
Running `rustc --crate-name parking_lot --edition=2018 /root/.cargo/registry/src/github.com-1ecc6299db9ec823/parking_lot-0.11.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 --cfg 'feature="default"' -C metadata=01e553f69513271f -C extra-filename=-01e553f69513271f --out-dir /tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps -L dependency=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps --extern instant=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/libinstant-8d8e286f6640e0bb.rmeta --extern lock_api=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/liblock_api-8e10e3c848fbd6d6.rmeta --extern parking_lot_core=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/libparking_lot_core-eee97183f997b675.rmeta --cap-lints allow -C target-feature=-crt-static`
Running `/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/build/pyo3-089b3f9e5ef423ad/build-script-build`
Compiling pyo3-macros-backend v0.13.1
Running `rustc --crate-name pyo3_macros_backend --edition=2018 /root/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-macros-backend-0.13.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C metadata=1c47d36fb0c032da -C extra-filename=-1c47d36fb0c032da --out-dir /tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps -L dependency=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps --extern proc_macro2=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/libproc_macro2-aa3871282eef8eab.rmeta --extern quote=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/libquote-4a1344d16195b0c6.rmeta --extern syn=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/libsyn-e836c33ca097f1fb.rmeta --cap-lints allow -C target-feature=-crt-static`
error[E0658]: use of unstable library feature 'str_strip': newly added
--> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-macros-backend-0.13.1/src/method.rs:144:18
|
144 | .strip_prefix(prefix)
| ^^^^^^^^^^^^
|
= note: see issue #67302 <https://github.com/rust-lang/rust/issues/67302> for more information

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
error: could not compile `pyo3-macros-backend`.

Caused by:
process didn't exit successfully: `rustc --crate-name pyo3_macros_backend --edition=2018 /root/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-macros-backend-0.13.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C metadata=1c47d36fb0c032da -C extra-filename=-1c47d36fb0c032da --out-dir /tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps -L dependency=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps --extern proc_macro2=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/libproc_macro2-aa3871282eef8eab.rmeta --extern quote=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/libquote-4a1344d16195b0c6.rmeta --extern syn=/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/deps/libsyn-e836c33ca097f1fb.rmeta --cap-lints allow -C target-feature=-crt-static` (exit code: 1)
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.html for specific
instructions for your platform.
3) Check our frequently asked questions for more information:
https://cryptography.io/en/latest/faq.html
4) Ensure you have a recent Rust toolchain installed.
=============================DEBUG ASSISTANCE=============================

error: cargo failed with code: 101

----------------------------------------
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
/ #

error[E0658]: use of unstable library feature 'str_strip': newly added

となった。

調べてみると、

rust と cargo は apk でインストールせずに、rustup を使うといいとのこと

https://rustup.rs/

apk add curl

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

/ # curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

/root/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory located at:

/root/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

/root/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile file located at:

/root/.profile

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


default host triple: x86_64-unknown-linux-musl
default toolchain: stable (default)
profile: default
modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1

info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-musl
info: syncing channel updates for 'stable-x86_64-unknown-linux-musl'
info: latest update on 2020-12-31, rust version 1.49.0 (e1884a8e3 2020-12-29)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
13.9 MiB / 13.9 MiB (100 %) 6.7 MiB/s in 2s ETA: 0s
info: downloading component 'rust-std'
21.5 MiB / 21.5 MiB (100 %) 6.8 MiB/s in 3s ETA: 0s
info: downloading component 'rustc'
76.9 MiB / 76.9 MiB (100 %) 7.2 MiB/s in 11s ETA: 0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: using up to 500.0 MiB of RAM to unpack components
info: installing component 'clippy'
info: installing component 'rust-docs'
13.9 MiB / 13.9 MiB (100 %) 7.6 MiB/s in 1s ETA: 0s
info: installing component 'rust-std'
21.5 MiB / 21.5 MiB (100 %) 11.2 MiB/s in 2s ETA: 0s
info: installing component 'rustc'
76.9 MiB / 76.9 MiB (100 %) 13.3 MiB/s in 5s ETA: 0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-unknown-linux-musl'

stable-x86_64-unknown-linux-musl installed - rustc 1.49.0 (e1884a8e3 2020-12-29)


Rust is installed now. Great!

To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH
environment variable. Next time you log in this will be done
automatically.

To configure your current shell, run:
source $HOME/.cargo/env
/ #

インストーラデフォルトで対話型

source $HOME/.cargo/env すれば、rustc ができるようになります。

結局こんな感じになりました

RUN apk add --no-cache --virtual=.build-deps \
... \
curl \
&& curl https://sh.rustup.rs -sSf | sh -s -- -y \
&& source /root/.cargo/env \
&& PIPENV_PIPFILE=/tmp/Pipfile pipenv install --dev --system --skip-lock --deploy \
&& rustup self uninstall -y \
&& apk del .build-deps \
&& rm -rf /var/cache/apk/* \
&& rm -rf /tmp/*

curl https://sh.rustup.rs -sSf | sh -s -- -y

で、対話を無効

アンインストールする時も

rustup self uninstall -y 

で対話を無効にする

現在の評価: 5

コメント

アーカイブ

2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011