英文:
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.py
,webdriver manager在ChromeDriverManager().install()行上显示错误。
错误如下:
英文:
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:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论