0
0

More than 1 year has passed since last update.

seleniumインストールに失敗したけどpipアップグレードして解消した

Last updated at Posted at 2022-01-27

macOSにseleniumをインストールしようとしたら何やらエラーが出ました。

結論から言うとpipアップグレードしたらエラーが解消してseleniumのインストールができました👍

こんな方にオススメ

  • pipコマンドで以下のようなエラーが発生して解決策を知りたい方
ERROR: Failed building wheel for cryptography
ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly

インストール失敗時のエラー内容

% pip3 install selenium
Defaulting to user installation because normal site-packages is not writeable
Collecting selenium
・・・(省略)
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
・・・(省略)
ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly
WARNING: You are using pip version 20.2.3; however, version 21.3.1 is available.
You should consider upgrading via the '/Library/Developer/CommandLineTools/usr/bin/python3 -m pip install --upgrade pip' command.

原因

正直真因はわかっていないですが、ちょっと調べた限り、cryptographyのビルドにRust compilerを使うけど、Rust compilerが見当たらないため出ているエラーと想定されます。

error: can't find Rust compiler
・・・(省略)
ERROR: Failed building wheel for cryptography
・・・(省略)
ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly

やったこと

stackoverflowを見たら、Rust compilerをインストールするか、pipをアップグレードするかを検討してみて。

と書いてあったし、エラー内容の最後にご丁寧にpipのアップグレードを検討してくださいと書いてくれていたので、まずは簡単そうなpipをアップグレードすることにしました。

% pip3 install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
 Downloading pip-21.3.1-py3-none-any.whl (1.7 MB)
    |████████████████████████████████| 1.7 MB 1.0 MB/s 
Installing collected packages: pip
 WARNING: The scripts pip, pip3 and pip3.8 are installed in '/Users/xxxx/Library/Python/3.8/bin' which is not on PATH.
 Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-21.3.1

なんかまだWARNING出てますけど、それは置いておいて、無事pipのアップグレードが完了しました!

念のため、バージョン確認しておきましょう。

% pip3 -V
pip 21.3.1 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)

最初に失敗したseleniumのインストールをやってみます!

% pip3 install selenium     
Defaulting to user installation because normal site-packages is not writeable
Collecting selenium
・・・(省略)
Installing collected packages: pycparser, cffi, attrs, sortedcontainers, sniffio, outcome, idna, h11, cryptography, async-generator, wsproto, urllib3, trio, pyOpenSSL, certifi, trio-websocket, selenium
Successfully installed async-generator-1.10 attrs-21.4.0 certifi-2021.10.8 cffi-1.15.0 cryptography-36.0.1 h11-0.13.0 idna-3.3 outcome-1.1.0 pyOpenSSL-21.0.0 pycparser-2.21 selenium-4.1.0 sniffio-1.2.0 sortedcontainers-2.4.0 trio-0.19.0 trio-websocket-0.9.2 urllib3-1.26.8 wsproto-1.0.0

すると、Successfully installedが出たので成功しました!やった〜🙌

pip20.2.3から21.3.1にアップグレードするにあたって、Rust compilerが含まれるようになったということなんですかね🤨

pipのChangelogにはそれらしいものがない気がしますが・・

なんにせよ、目的は達成できたので良しとします!

なにか真因がわかる方いらっしゃいましたら、是非教えてください〜!

上記解決しました!

「pip」ではなく「cryptography」側の問題で、pipをアップグレードすることで「Rustでコンパイル済み」の「パッケージ(cryptography wheel)」を取って来ていた、ということですね!

上記の【Installing cryptography fails with error: Can not find Rust compiler】より。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0