Tyler Anderson
Tyler Anderson

Reputation: 110

selenium, chromedriver_autoinstaller, & pyinstaller in onefile

I am trying to create a onefile .exe using pyinstaller that will utilize chromedriver_autoinstaller so that the chromedriver is always up to date. The code works fine when run within the IDE but once I use pyinstaller to create the .exe it throws the 'Specific issue with chrome_autoinstaller' message. Because the chromedriver_autoinstaller is not working, the program then cannot find chromedriver. The program does work in an .exe without the autoinstaller by directly referencing the chromedriver file path but I would prefer to utilize this package if possible.

class LoginPCC:
    def __init__(self):  # create an instance of this class. Begins by logging in
        try:
            chrome_options = webdriver.ChromeOptions()
            settings = {
                "recentDestinations": [{
                    "id": "Save as PDF",
                    "origin": "local",
                    "account": "",
                }],
                "selectedDestinationId": "Save as PDF",
                "version": 2
            }
            prefs = {'printing.print_preview_sticky_settings.appState': json.dumps(settings), 
            "plugins.always_open_pdf_externally": True}
            chrome_options.add_experimental_option('prefs', prefs)
            chrome_options.add_argument('--kiosk-printing')
            try:
                chromedriver_autoinstaller.install()
            except:
                print('Specific issue with chrome_autoinstaller')
            try:
                self.driver = webdriver.Chrome(options=chrome_options)
            except:
                print('Cannot find chromedriver')

python 3.7 pyinstaller 4.0.dev selenium 4.141.0 chromedriver-autoinstaller 0.2

Upvotes: 2

Views: 5584

Answers (1)

Sergiy Savelyev
Sergiy Savelyev

Reputation: 179

The below worked for me:

chromedriver_autoinstaller.install(cwd=True)

When you launch your EXE first time, a new folder will be created in a folder where you place your EXE. This is where the chromedriver will be stored. This is not the prettiest solution, but it works.

Upvotes: 5

Related Questions