首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在pyinstaller中使用webdriver-manager时出错

在pyinstaller中使用webdriver-manager时出错
EN

Stack Overflow用户
提问于 2021-01-03 05:16:58
回答 1查看 312关注 0票数 2

我的webdriver-manager运行得很好,但是当我用pyinstaller制作.exe文件时,我得到了下面的错误。我发现,如果我不将--noconsole放到pyinstaller命令中,它将会工作,但如果使用--noconsole,程序将无法工作。下面是我的代码:

代码语言:javascript
复制
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://www.google.com/")
driver.quit()

下面是我如何使用pyinstaller创建.exe文件:

代码语言:javascript
复制
pyinstaller --onefile --noconsole script.py

下面是我得到的错误:

代码语言:javascript
复制
Traceback (most recent call last):
  File "script.py", line 797, in program2
  File "webdriver_manager\chrome.py", line 23, in __init__
  File "webdriver_manager\driver.py", line 54, in __init__
  File "webdriver_manager\utils.py", line 139, in chrome_version
  File "os.py", line 983, in popen
  File "subprocess.py", line 804, in __init__
  File "subprocess.py", line 1142, in _get_handles
OSError: [WinError 6] The handle is invalid

感谢您的帮助!

EN

回答 1

Stack Overflow用户

发布于 2021-06-16 19:11:16

如果您使用的是webdriver_manager > 3.4.2的版本,则此错误必须已经修复。

如果您使用的是webdriver_manager <= 3.4.2版本,则错误仍然存在。

Here是项目的Github上的拉取请求讨论,它修复了这个问题。

为了自己修复这个错误,我们需要在webdriver_manager/utils.py - import附加模块中进行更改,并更改两个函数:

开头的

  1. 导入subprocess模块

导入子流程

  1. 请在def chrome_version()中查找以下代码片段:

使用标准输出(Cmd)作为流: stdout = stream.read()

  1. 并将其更改为以下内容:

使用subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.DEVNULL,stdin=subprocess.DEVNULL,shell=True)作为流: stdout = stream.communicate().decode()

def firefox_version().重复上述步骤的

强烈建议仅在您确定可以恢复更改的情况下才执行上述所有操作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65544189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档