Pyinstaller打包时,希望隐藏driver控制台黑框的情况,解决方法如下:
1、
找到文件service.py(网上很多文章说是找services.py,但是我自己的selenium安装完只能有service.py,各位根据自己的情况看看是service.py还是services.py),具体路径为:C:\ProgramData\Anaconda3\Lib\site-packages\selenium\webdriver\common\service.py,
注意是common文件夹下的service.py
?2、
打开service.py文件,找到函数start,应该是在第61行的位置
def start(self):
"""
Starts the Service.
:Exceptions:
- WebDriverException : Raised either when it can't start the service
or when it can't connect to the service
"""
try:
cmd = [self.path]
cmd.extend(self.command_line_args())
self.process = subprocess.Popen(cmd, env=self.env,
close_fds=platform.system() != 'Windows',
stdout=self.log_file,
stderr=self.log_file,
stdin=PIPE)
3、
在stdin=PIPE后面加上一段代码creationflags=134217728,变成:
def start(self):
"""
Starts the Service.
:Exceptions:
- WebDriverException : Raised either when it can't start the service
or when it can't connect to the service
"""
try:
cmd = [self.path]
cmd.extend(self.command_line_args())
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)
这里注意一下,网上很多在creationflags=134217728后面加了逗号,导致出错,这里千万别多打一个逗号。
4、
保存文件,selenium不宰弹出黑框
?
|