在 pyinstaller 中以窗口模式导出到 EXE 后,Selenium 不起作用 [英] Selenium don't work after exporting to EXE in windowed mode in pyinstaller

查看:88
本文介绍了在 pyinstaller 中以窗口模式导出到 EXE 后,Selenium 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个需要使用硒的 PyQt4 应用程序.在开发过程中一切正常,但是当我通过pyinstaller没有控制台导出到单个文件 EXE时,它会产生以下回溯错误:

I am making an PyQt4 application where I need to use selenium. Everything works fine while development but when I exported to single file EXE, by pyinstaller and without console, it produces following traceback error:

[WinError6] The handle is invalid

当我在 console = True(在 pyinstaller 规范文件中)导出它时不会发生这种情况,该错误仅没有控制台产生.

This doesn't happen when I export it when console = True (in pyinstaller spec file), The error is produced only without console.

产生的错误在以下行:

driver = webdriver.Chrome(executable_path="chromedriver.exe")

我的规格:

Python:3.4
架构:64 位
硒:3.6.0
Pyinstaller:3.3
操作系统:Windows 10

我用谷歌搜索了大约 1 小时,但找不到任何解决方案:(

I googled about 1 hour but couldn't find any solution :(

推荐答案

经过大量研究,我找到了解决上述问题的方法.

After a lot of research, I found a solution for the above problem.

您只需要编辑文件:
C:\Python34\Lib\site-packages\selenium\webdriver\common\service.py

更改以下行:

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

到:

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

即使在开发过程中以及部署到 EXE 之后,这也能正常工作.

This will work even while development and also after deploying to EXE.

可能是硒错误.

这篇关于在 pyinstaller 中以窗口模式导出到 EXE 后,Selenium 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆