Reputation: 1277
I'm using chromedriver in headless mode. I compile the script using pyinstaller as one exe file. Everything works fine, except that I get the following console window whenever I open a chrome page:
I've tried the options --windowed
alone, --noconsole
alone, --windowed
and --noconsole
together but I still get this window.
How can I get rid of it?
Upvotes: 2
Views: 3291
Reputation: 11
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.
Upvotes: 1
Reputation: 1277
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)
Upvotes: 8