---
slug: "python-cryptography-pep-517-rust-E0658"
title: "Python cryptography がインストールできなくなったら rustup で rust をインストールする"
description: "Mac の Quick Look や Finder で Display Link 経由ディスプレイに表示すると画面が再描画されない問題への対処。"
url: "https://www.ytyng.com/blog/python-cryptography-pep-517-rust-E0658"
publish_date: "2021-02-08T14:34:50Z"
created: "2021-02-08T14:34:50Z"
updated: "2026-05-11T13:21:51.227Z"
categories: ["Python"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20250605/52cae6aa3ecc42a5bc0809434e478387.png.webp?width=768"
has_video: true
has_music: true
video_urls: ["https://media.ytyng.net/ytyng-blog/192/featured-video-1.mp4", "https://media.ytyng.net/ytyng-blog/192/featured-video-2.mp4", "https://media.ytyng.net/ytyng-blog/192/featured-video-3.mp4"]
music_urls: ["https://media.ytyng.net/ytyng-blog/192/featured-music-192-3.mp3", "https://media.ytyng.net/ytyng-blog/192/featured-music-192-4.mp3"]
lang: "ja"
---

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

<p>Alpine の Dockerfile 内の Pipenv install が失敗する。</p>
<p>cryptography 3.4.1 のインストールで、&nbsp;ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly で失敗している。</p>
<p></p>
<p>試しに、pipenv ではなく、</p>
<p>pip install cryptography してみると</p>
<p></p>
<pre>#10 32.68 [pipenv.exceptions.InstallError]: Collecting cryptography&gt;=1.4<br />#10 32.68 [pipenv.exceptions.InstallError]: Using cached cryptography-3.4.4.tar.gz (545 kB)<br />#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</pre>
<pre> generating cffi module 'build/temp.linux-x86_64-3.8/_padding.c'<br /> creating build/temp.linux-x86_64-3.8<br /> generating cffi module 'build/temp.linux-x86_64-3.8/_openssl.c'<br /> running build_rust<br /> <br /> =============================DEBUG ASSISTANCE=============================<br /> If you are seeing a compilation error please try the following steps to<br /> successfully install cryptography:<br /> 1) Upgrade to the latest pip and try again. This will fix errors for most<br /> users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip<br /> 2) Read https://cryptography.io/en/latest/installation.html for specific<br /> instructions for your platform.<br /> 3) Check our frequently asked questions for more information:<br /> https://cryptography.io/en/latest/faq.html<br /> 4) Ensure you have a recent Rust toolchain installed.<br /> =============================DEBUG ASSISTANCE=============================<br /> <br /> error: Can not find Rust compiler<br /> ----------------------------------------<br /> ERROR: Failed building wheel for cryptography<br />Failed to build cryptography<br />ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly<br />/ # </pre>
<p>Rust が必要とのこと。</p>
<p>現在のバージョンは cryptography 3.4.1 、Rust でビルドするようになった。</p>
<p></p>
<p>FAQを見てみると</p>
<p><a href="https://cryptography.io/en/latest/faq.html">https://cryptography.io/en/latest/faq.html</a></p>
<p></p>
<p>今回のバージョンに限り、<span>CRYPTOGRAPHY_DONT_BUILD_RUST の環境変数で、Rust を使わないでビルドできるらしい。</span></p>
<p><span>これは最終手段としよう。</span></p>
<p></p>
<p>試しに rust, cargo をインストールしてやってみる</p>
<p></p>
<p>apk add rust cargo</p>
<p>して、</p>
<p><span>pip install cryptography</span></p>
<pre> 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`<br /> 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`<br /> Compiling parking_lot v0.11.1<br /> 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`<br /> Running `/tmp/pip-install-v1h5w2m6/cryptography_7f388e3637a141d696bf039cf3d904e3/src/rust/target/release/build/pyo3-089b3f9e5ef423ad/build-script-build`<br /> Compiling pyo3-macros-backend v0.13.1<br /> 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`<br /> error[E0658]: use of unstable library feature 'str_strip': newly added<br /> --&gt; /root/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-macros-backend-0.13.1/src/method.rs:144:18<br /> |<br /> 144 | .strip_prefix(prefix)<br /> | ^^^^^^^^^^^^<br /> |<br /> = note: see issue #67302 &lt;https://github.com/rust-lang/rust/issues/67302&gt; for more information<br /> <br /> error: aborting due to previous error<br /> <br /> For more information about this error, try `rustc --explain E0658`.<br /> error: could not compile `pyo3-macros-backend`.<br /> <br /> Caused by:<br /> 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)<br /> warning: build failed, waiting for other jobs to finish...<br /> error: build failed<br /> <br /> =============================DEBUG ASSISTANCE=============================<br /> If you are seeing a compilation error please try the following steps to<br /> successfully install cryptography:<br /> 1) Upgrade to the latest pip and try again. This will fix errors for most<br /> users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip<br /> 2) Read https://cryptography.io/en/latest/installation.html for specific<br /> instructions for your platform.<br /> 3) Check our frequently asked questions for more information:<br /> https://cryptography.io/en/latest/faq.html<br /> 4) Ensure you have a recent Rust toolchain installed.<br /> =============================DEBUG ASSISTANCE=============================<br /> <br /> error: cargo failed with code: 101<br /> <br /> ----------------------------------------<br /> ERROR: Failed building wheel for cryptography<br />Failed to build cryptography<br />ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly<br />/ # </pre>
<p></p>
<pre>error[E0658]: use of unstable library feature 'str_strip': newly added</pre>
<p>となった。</p>
<p>調べてみると、</p>
<p>rust と cargo は apk でインストールせずに、rustup を使うといいとのこと</p>
<p></p>
<p><a href="https://rustup.rs/">https://rustup.rs/</a></p>
<p></p>
<p>apk add curl</p>
<p>curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh</p>
<p></p>
<pre>/ # curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh<br />info: downloading installer<br /><br />Welcome to Rust!<br /><br />This will download and install the official compiler for the Rust<br />programming language, and its package manager, Cargo.<br /><br />Rustup metadata and toolchains will be installed into the Rustup<br />home directory, located at:<br /><br /> /root/.rustup<br /><br />This can be modified with the RUSTUP_HOME environment variable.<br /><br />The Cargo home directory located at:<br /><br /> /root/.cargo<br /><br />This can be modified with the CARGO_HOME environment variable.<br /><br />The cargo, rustc, rustup and other commands will be added to<br />Cargo's bin directory, located at:<br /><br /> /root/.cargo/bin<br /><br />This path will then be added to your PATH environment variable by<br />modifying the profile file located at:<br /><br /> /root/.profile<br /><br />You can uninstall at any time with rustup self uninstall and<br />these changes will be reverted.<br /><br />Current installation options:<br /><br /><br /> default host triple: x86_64-unknown-linux-musl<br /> default toolchain: stable (default)<br /> profile: default<br /> modify PATH variable: yes<br /><br />1) Proceed with installation (default)<br />2) Customize installation<br />3) Cancel installation<br />&gt;1<br /><br />info: profile set to 'default'<br />info: default host triple is x86_64-unknown-linux-musl<br />info: syncing channel updates for 'stable-x86_64-unknown-linux-musl'<br />info: latest update on 2020-12-31, rust version 1.49.0 (e1884a8e3 2020-12-29)<br />info: downloading component 'cargo'<br />info: downloading component 'clippy'<br />info: downloading component 'rust-docs'<br /> 13.9 MiB / 13.9 MiB (100 %) 6.7 MiB/s in 2s ETA: 0s<br />info: downloading component 'rust-std'<br /> 21.5 MiB / 21.5 MiB (100 %) 6.8 MiB/s in 3s ETA: 0s<br />info: downloading component 'rustc'<br /> 76.9 MiB / 76.9 MiB (100 %) 7.2 MiB/s in 11s ETA: 0s<br />info: downloading component 'rustfmt'<br />info: installing component 'cargo'<br />info: using up to 500.0 MiB of RAM to unpack components<br />info: installing component 'clippy'<br />info: installing component 'rust-docs'<br /> 13.9 MiB / 13.9 MiB (100 %) 7.6 MiB/s in 1s ETA: 0s<br />info: installing component 'rust-std'<br /> 21.5 MiB / 21.5 MiB (100 %) 11.2 MiB/s in 2s ETA: 0s<br />info: installing component 'rustc'<br /> 76.9 MiB / 76.9 MiB (100 %) 13.3 MiB/s in 5s ETA: 0s<br />info: installing component 'rustfmt'<br />info: default toolchain set to 'stable-x86_64-unknown-linux-musl'<br /><br /> stable-x86_64-unknown-linux-musl installed - rustc 1.49.0 (e1884a8e3 2020-12-29)<br /><br /><br />Rust is installed now. Great!<br /><br />To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH<br />environment variable. Next time you log in this will be done<br />automatically.<br /><br />To configure your current shell, run:<br />source $HOME/.cargo/env<br />/ # </pre>
<p></p>
<p>インストーラデフォルトで対話型</p>
<p>source $HOME/.cargo/env すれば、rustc ができるようになります。</p>
<p></p>
<p>結局こんな感じになりました</p>
<p></p>
<pre><span>RUN </span>apk add <span>--</span>no-cache <span>--</span>virtual=.build-deps \<br />    ... \<br />    curl \<br />    &amp;&amp; curl https://sh.rustup.rs -sSf | sh -s -- -y  \<br />    &amp;&amp; source /root/.cargo/env  \<br />    &amp;&amp; PIPENV_PIPFILE=/tmp/Pipfile pipenv install --dev --system --skip-lock --deploy&nbsp;\<br />    &amp;&amp; rustup self uninstall -y \<br />    &amp;&amp; apk del .build-deps \<br />    &amp;&amp; rm -rf /var/cache/apk/* \<br />    &amp;&amp; rm -rf /tmp/*</pre>
<p></p>
<pre>curl https://sh.rustup.rs -sSf | sh -s -- -y</pre>
<p>で、対話を無効</p>
<p></p>
<p>アンインストールする時も</p>
<pre>rustup self uninstall -y </pre>
<p>で対話を無効にする</p>
