Getting rid of chromedirver console window with pyinstaller Getting rid of chromedirver console window with pyinstaller selenium selenium

Getting rid of chromedirver console window with pyinstaller


I was able to find the following answer and it's working perfectly for me:

To avoid getting console windows for chromedriver, open the file

Python\Lib\site-packages\selenium\webdriver\common\service.py

and change

self.process = subprocess.Popen(cmd, env=self.env, close_fds=platform.system() != 'Windows', stdout=self.log_file, stderr=self.log_file, stdin=PIPE)

To:

self.process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE ,stderr=PIPE, shell=False, creationflags=0x08000000)


I had a similar issue, I'd like to share how I fixed it. First I'll describe the context:

-- My script worked well, it opened chrome windows normally (not headless).

-- I used pyinstaller (with the onefile and noconsole commands).

-- The EXE worked but every time it opened a chrome window, it opened a console window as well, I don't remember what the window said, but it wasn't an error.

-- I tried the solution that Ahmed post, and it worked that day.

-- Next day I tried the EXE in various computers, and the problem came back.

-- I posponed that problem since it wasn't a fatal error and there were more important issues to resolve in my app. So while I was trying to fix another issue, I found this answer: https://stackoverflow.com/a/56839122/13988982.

-- Basically it said that changing the order of the commands that you use when you run pyinstaller, actually affects how the EXE file is packaged. (I'm not sure why).

-- I ran: pyinstaller --add-binary "chromedriver.exe;." --noconsole --onefile myApp.py

And that finally made the console window not to show anymore.

Hope this is useful for anyone.