I am trying to add Chromedriver inside an executable in pyinstaller. While this is possible it seems that I get the below error message when trying to run this on another c
Use --add-binary
to bundle the driver in the application:
pyinstaller -F --add-binary "C:\drivers\chromedriver.exe";"." script.py
and use sys._MEIPASS
to get the folder where the driver is extracted:
import sys, os, time
from selenium import webdriver
if __name__ == "__main__":
if getattr(sys, 'frozen', False):
# executed as a bundled exe, the driver is in the extracted folder
chromedriver_path = os.path.join(sys._MEIPASS, "chromedriver.exe")
driver = webdriver.Chrome(chromedriver_path)
else:
# executed as a simple script, the driver should be in `PATH`
driver = webdriver.Chrome()
driver.get("https://stackoverflow.com")
time.sleep(5)
driver.quit()