每当我尝试 运行 export_png 时,Bokeh 都会抛出一个 RuntimeError

Bokeh throws a RuntimeError whenever I try to run export_png

我刚刚更新了我的所有 python 包,但我的一些脚本无法正常工作。具体来说,Bokeh 在 export_png 函数方面存在问题。

通常只是将图表的副本保存到特定目录。现在我收到这个错误:

Traceback (most recent call last):

  File "C:\Users\ethan\projects\health\chart.py", line 112, in <module>
    p = column(make_chart(False), make_chart(True))

  File "C:\Users\ethan\projects\health\chart.py", line 106, in make_chart
    export_png(p, filename = name + '.png')

  File "C:\ProgramData\Anaconda3\lib\site-packages\bokeh\io\export.py", line 97, in export_png
    image = get_screenshot_as_png(obj, width=width, height=height, driver=webdriver, timeout=timeout)

  File "C:\ProgramData\Anaconda3\lib\site-packages\bokeh\io\export.py", line 201, in get_screenshot_as_png
    web_driver = driver if driver is not None else webdriver_control.get()

  File "C:\ProgramData\Anaconda3\lib\site-packages\bokeh\io\webdriver.py", line 118, in get
    self.current = self.create()

  File "C:\ProgramData\Anaconda3\lib\site-packages\bokeh\io\webdriver.py", line 122, in create
    driver = self._create(kind)

  File "C:\ProgramData\Anaconda3\lib\site-packages\bokeh\io\webdriver.py", line 140, in _create
    raise RuntimeError("Neither firefox and geckodriver nor a variant of chromium browser and " \

RuntimeError: Neither firefox and geckodriver nor a variant of chromium browser and chromedriver are available on system PATH. You can install the former with 'conda install -c conda-forge firefox geckodriver'.

Chrome 在我的电脑上运行良好,我现在正在使用它。我不确定为什么 bokeh 需要为此使用浏览器,因为我只是制作一个 png 文件,但是有没有办法在不安装 firefox 的情况下解决这个问题?我更愿意继续使用 chrome。

I'm not sure why bokeh needs to use a browser for this because I'm just making a png file

那是因为为了创建该 PNG 文件,需要渲染由 Bokeh 创建的 HTML 文档。以前,Bokeh 为此使用 PhantomJS,但该项目现在已过时且无人维护。

is there a way to fix this without installing firefox?

正如错误信息所说,如果你想使用 chromium 浏览器(Google Chrome 是),你必须在你的 PATH 上有 chromedriver。如果您正在使用 conda ,您可以尝试在用于 Bokeh 的相同环境中通过 conda install -c conda-forge python-chromedriver-binary 安装它。