pyinstallerの実行可能ファイルにChromedriverを追加しようとしています。これは可能ですが、これは別のコンピュータでこれを実行しようとすると、以下のエラーメッセージが表示されるようです。pyinstallerをChromedriverで実行しています
私はこのoneを含む多くの投稿を試しましたが、残念ながら、これは望ましい結果を提供していません。最高のケースは、chrome exeが役に立たなかった同じフォルダにあったときに自分のコンピュータで実行できるということでした。
コード1:
Main.py
from selenium import webdriver
driver = webdriver.Chrome()
別のPC上で動作しているとき、私は何を得る:
エラー1:
クロームのパスを見つけることができません
C:\Users\Aperture Science\Desktop\1>123.exe
Traceback (most recent call last):
File "site-packages\selenium\webdriver\common\service.py", line 74, in start
File "subprocess.py", line 709, in __init__
File "subprocess.py", line 997, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 42, in <module>
File "main.py", line 33, in main
File "site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
File "site-packages\selenium\webdriver\common\service.py", line 81, in start
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
[2228] Failed to execute script main
どうすればこの問題を回避できますか?
私は提供されたリンクから何を得る:
コード2:
from selenium import webdriver
import os, sys, inspect
current_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe()))[0]))
chromedriver = os.path.join(current_folder,"chromedriver.exe")
driver = webdriver.Chrome(executable_path = chromedriver)
driver.get("http://www.imdb.com/")
は、設定されたパスにクロムexeファイルが必要ですが、同梱クロム読んでいません。そのため、パッケージ化されたクロムは必要に応じて機能しません。
をだからあなたの質問は何ですか?あなたはどこにいるのですか?エラーが表示されますか?エラースタックトレースで質問を更新してください。 – DebanjanB
[link](https://stackoverflow.com/questions/41030257/is-there-a-way-to-bundle-a-binary-file-such-as-chromedriver-with-single-file)あなたのポストからの答えがありますが、あなたのコードがそれを無視している何らかの理由があります。ターゲットマシンが明らかに 'PATH'環境変数にドライバを持っておらず、' webdriver.Chrome() 'へのパスを提供していないとすれば、あなたのサンプルがうまくいくと思いますか? @FlorentB。 –
。私は投稿した別のエラーを取得します。また、chromeriverは、パッケージ化されたクロムを検出したくないので、実行可能ファイルの横のフォルダに置かなければなりません。私はあなたが現在のフォルダのためにクロムバイナリの周りをどのように得るかについて完全にはわかりません。 –