1

I did not know how to create an executable python program before I asked here. Thankfully I received a fast answer and was able to convert my script to an executable program. The executable works perfect but only on my computer. These are the two error's I am receiving, I feel like I need to modify the script in order to locate the chrome driver I am not sure where Pyinstaller saved everything.

Exception in Tkinter callback
Traceback (most recent call last):
File "site-packages\selenium\webdriver\common\service.py", line 76, in start
File "subprocess.py", line 775, in __init__
File "subprocess.py", line 1178, 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 "tkinter\__init__.py", line 1705, in __call__
File "MarijuanaDoctors.py", line 25, in search
File "site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
File "site-packages\selenium\webdriver\common\service.py", line 83, 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
1
  • Short answer: Pyinstaller does not save the chromedriver, only the python file which interacts with the chromedriver. To store additional data check the pyinstaller documentation. Python -(uses)-> chromedriver.exe -(to control)-> chrome.exe. The path to chromedriver.exe and chrome.exe have to be implicitly or explicitly defined in your python code. Commented Feb 1, 2019 at 0:14

1 Answer 1

1

You can bundle your "chromedriver.exe" along with your script using Pyinstaller like this:

pyinstaller --add-binary="localpathtochromedriver;." myscript.py

This will copy the "chromedriver.exe" file in the same folder as your main .exe(Or in case of single file option of pyinstaller, this fill will be extracted in temp folder while using exe program).

In your script you can check if you are running the script normally or from bundled(exe file) mode, and choose path to chromedriver.exe accordingly.(This change in script can be common for Single file/folder bundle option of pyinstaller)

import sys
if getattr(sys, 'frozen', False ):
    #Running from exe, so the path to exe is saved in sys._MEIPASS
    chrome_driver = os.path.join(sys._MEIPASS, "chromedriver.exe")
else:
    chrome_driver = 'localpathtochromedriver.exe'
driver = webdriver.Chrome(executable_path=chrome_driver)

You can read about this in docs here.

Limitation: The user of your .exe should have Chrome installed on their system and Chrome version should work with the chromedriver which is bundled.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.