完美解决Pyinstaller打包爬虫chromedrive去除控制台

16743598:

1、问题

用 Pyinstaller打包后,运行exe文件时总是出现driver控制台窗口

2、解决方案:

找到

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

增加代码

creationflags=134217728)

最终样式:

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

同时,spec文件中

exe 中的 console=False

如果还有问题,尝试安装下pyinstaller 5.0版本

3、不可行方案

from win32process import CREATE_NO_WINDOW
creationflags=CREATE_NO_WINDOW

还是会报错

引用:
pyinstaller --noconsole 后selenium还弹出 chromedriver 黑色命令窗口
https://www.jianshu.com/p/a5ed0b2b5cc3

hide chromeDriver console in python

猜你喜欢

转载自blog.csdn.net/weixin_43818488/article/details/128827370