Running pyinstaller another pc with Chromedriver Running pyinstaller another pc with Chromedriver selenium selenium

Running pyinstaller another pc with Chromedriver


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, timefrom selenium import webdriverif __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()