我的webdriver-manager运行得很好,但是当我用pyinstaller制作.exe文件时,我得到了下面的错误。我发现,如果我不将--noconsole放到pyinstaller命令中,它将会工作,但如果使用--noconsole,程序将无法工作。下面是我的代码:
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文件:
pyinstaller --onefile --noconsole script.py下面是我得到的错误:
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感谢您的帮助!
发布于 2021-06-16 19:11:16
如果您使用的是webdriver_manager > 3.4.2的版本,则此错误必须已经修复。
如果您使用的是webdriver_manager <= 3.4.2版本,则错误仍然存在。
Here是项目的Github上的拉取请求讨论,它修复了这个问题。
为了自己修复这个错误,我们需要在webdriver_manager/utils.py - import附加模块中进行更改,并更改两个函数:
开头的
subprocess模块导入子流程
def chrome_version()中查找以下代码片段:使用标准输出(Cmd)作为流: stdout = stream.read()
使用subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.DEVNULL,stdin=subprocess.DEVNULL,shell=True)作为流: stdout = stream.communicate().decode()
对def firefox_version().重复上述步骤的
强烈建议仅在您确定可以恢复更改的情况下才执行上述所有操作。
https://stackoverflow.com/questions/65544189
复制相似问题