LoginSignup
5
3

More than 3 years have passed since last update.

No such file or directory: 'chromedriver': 'chromedriver'の解決

Posted at

seleniumを使おうと考えて、、

Python + Selenium で Chrome の自動操作を一通りにならってseleniumの設定を行っていました。
非headlessモードでテストの部分でエラーが、、、
エラーメッセージ:
` File "/Users/[ユーザ名]/.pyenv/versions/3.7.3/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Users/[ユーザ名]/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py", line 775, in init
restore_signals, start_new_session)
File "/Users/[ユーザ名]/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "test.py", line 4, in
driver = webdriver.Chrome()
File "/Users/[ユーザ名]/.pyenv/versions/3.7.3/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in init
self.service.start()
File "/Users/[ユーザ名]/.pyenv/versions/3.7.3/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home`

解決

seleniumが起動しないという似た質問を見つけたので、そこの解決方法に従いました。
原因としては、解決方法にあった通りchromedriver-binaryとchromeのバージョンが異なっていたから、
自分のchromedriver-binaryのバージョンはchromedriver-binary-81.0.4044.20.0に対してchromeのバージョンは80.0.3987.132

バージョンを変更しようと考え、pip install chromedriver-binary==80.0.3987.132とchromeのバージョンに合わせたchromedriverをインストールしようと考えたら、
ERROR: Could not find a version that satisfies the requirement chromedriver-binary==80.0.3987.132 (from versions: 2.29.1, 2.31.1, 2.33.1, 2.34.0, 2.35.0, 2.35.1, 2.36.0, 2.37.0, 2.38.0, 2.39.0, 2.40.1, 2.41.0, 2.42.0, 2.43.0, 2.44.0, 2.45.0, 2.46.0, 70.0.3538.16.0, 70.0.3538.67.0, 70.0.3538.97.0, 71.0.3578.30.0, 71.0.3578.33.0, 71.0.3578.80.0, 71.0.3578.137.0, 72.0.3626.7.0, 72.0.3626.69.0, 73.0.3683.20.0, 73.0.3683.68.0, 74.0.3729.6.0, 75.0.3770.8.0, 75.0.3770.90.0, 75.0.3770.140.0, 76.0.3809.12.0, 76.0.3809.25.0, 76.0.3809.68.0, 76.0.3809.126.0, 77.0.3865.10.0, 77.0.3865.40.0, 78.0.3904.11.0, 78.0.3904.70.0, 78.0.3904.105.0, 79.0.3945.16.0, 79.0.3945.36.0, 80.0.3987.16.0, 80.0.3987.106.0, 81.0.4044.20.0)
ERROR: No matching distribution found for chromedriver-binary==80.0.3987.132

と怒られる。
必ずしもchromeのバージョンのchromedriver-binaryがあるわけではないらしい。
そこで一番近そうなchromedriver-binary==80.0.3987.106.0をインストール。
(他の80.0のバージョンでは試していませんが、近いバージョンを選べば良さそう)

最後にimport chromedriver_binaryをテストケースの冒頭に加えてあげたらテストケースが実行できました。

感想

自分のchromeは最新だったのに、chromedriver_binaryの最新バージョンとバージョンが一致しなかったのは何故、、、

参照

Python + Selenium で Chrome の自動操作を一通り
seleniumが起動しない

5
3
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
5
3