webdriver-manager getting error as executable

huangapple go评论69阅读模式
英文:

webdriver-manager getting error as executable

问题

我有一个使用ChromeDriverManager().install()来获取最新chromedriver的Python脚本。

代码片段:

    def get_location():
        exe_path = "C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe"

        service = Service(ChromeDriverManager().install())
        options = Options()
        options.add_argument('--headless=new')
        options.binary_location = exe_path

        service.creation_flags = CREATE_NO_WINDOW

        driver = webdriver.Chrome(service=service, options=options)

当使用main.py脚本运行时,一切正常,没有错误。但是当我将Python文件main.py转换为可执行文件main.exe时,使用pyinstaller --onefile --noconsole main.pywebdriver manager在ChromeDriverManager().install()行上显示错误

错误如下:

webdriver-manager getting error as executable

英文:

I have a python script which uses ChromeDriverManager().install() for getting the latest chromedriver.

A snippet of the code:

def get_location():
    exe_path = "C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe"

    service = Service(ChromeDriverManager().install())
    options = Options()
    options.add_argument('--headless=new')
    options.binary_location = exe_path

    service.creation_flags = CREATE_NO_WINDOW

    driver = webdriver.Chrome(service=service, options=options)

Everything works fine when run using the main.py script, no error. But when I convert the python file, main.py to an executable, main.exe using pyinstaller --onefile --noconsole main.py the webdriver manager shows error on the ChromeDriverManager().install() line.

The error is this:

webdriver-manager getting error as executable

What should I do to avoid this error?

答案1

得分: 0

Add these lines at the beginning of your function. This disables Webdriver-manager logs. The error is caused by not having a console to view the logs.

英文:
os.environ['WDM_LOG'] = str(logging.NOTSET)
os.environ['WDM_PROGRESS_BAR'] = str(0)

Add these lines at the beginning of your function. This disables Webdriver-manager logs. The error is caused by not having a console to view the logs.

huangapple
  • 本文由 发表于 2023年5月25日 03:15:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76326750.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定