Python 硒-don';在pyinstaller中以窗口模式导出为EXE后无法工作
我正在制作一个需要使用selenium的PyQt4应用程序。开发过程中一切正常,但当我通过pyinstaller导出到单文件EXE时,在没有控制台的情况下,会产生以下回溯错误:Python 硒-don';在pyinstaller中以窗口模式导出为EXE后无法工作,python,python-3.x,selenium,pyinstaller,Python,Python 3.x,Selenium,Pyinstaller,我正在制作一个需要使用selenium的PyQt4应用程序。开发过程中一切正常,但当我通过pyinstaller导出到单文件EXE时,在没有控制台的情况下,会产生以下回溯错误: [WinError6] The handle is invalid 当我将其导出为console=True(在pyinstaller spec文件中)时不会发生这种情况,只有在没有console的情况下才会产生错误 产生的错误在以下行中: driver = webdriver.Chrome(executable_pat
[WinError6] The handle is invalid
当我将其导出为console=True
(在pyinstaller spec文件中)时不会发生这种情况,只有在没有console的情况下才会产生错误
产生的错误在以下行中:
driver = webdriver.Chrome(executable_path="chromedriver.exe")
self.process = subprocess.Popen(cmd, env=self.env,
close_fds=platform.system() != 'Windows',
stdout=self.log_file, stderr=self.log_file)
我的规格:
Python:3.4体系结构:64位
硒:3.6.0
Pyinstaller:3.3
操作系统:Windows 10
我在谷歌上搜索了大约1个小时,但找不到任何解决方案:(经过大量研究,我找到了上述问题的解决方案 您只需编辑文件:
C:\Python34\Lib\site packages\selenium\webdriver\common\service.py
更改以下行:
driver = webdriver.Chrome(executable_path="chromedriver.exe")
self.process = subprocess.Popen(cmd, env=self.env,
close_fds=platform.system() != 'Windows',
stdout=self.log_file, stderr=self.log_file)
致:
即使在开发期间和部署到EXE之后,这也会起作用
可能是selenium错误。我发现pyinstaller没有在dist文件夹中创建chromedriver.exe的副本。
将chromedriver.exe文件复制到那里为我解决了问题。是否有异常堆栈跟踪?是的,这是回溯异常。更新问题中的堆栈跟踪,而不是注释中的堆栈跟踪。我发现保持关闭\u fds=platform.system()!='Windows'参数确保在关闭应用程序时IEDriverServer.exe进程始终处于关闭状态。这可能是首选,否则会导致多个不可见进程。