You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Google Colab中从Bokeh绘图导出SVG或PDF文件?

在Google Colab中用Bokeh保存SVG的解决方法

你遇到的错误翻译过来是:

运行时错误:要使用bokeh.io的图片导出功能,你需要安装selenium(执行conda install selenium或pip install selenium)

在Colab环境下,按以下步骤解决:

  • 先安装selenium依赖,在代码单元格运行:

    !pip install selenium
    
  • 接着安装Chrome浏览器和ChromeDriver(Colab是无界面环境,需要这个来渲染图形):

    !apt-get update
    !apt install chromium-chromedriver
    
  • 配置selenium使用无头Chrome,在绘图代码前添加这段配置:

    import sys
    sys.path.insert(0,'/usr/lib/chromium-browser/chromedriver')
    
    from selenium import webdriver
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--disable-dev-shm-usage')
    driver = webdriver.Chrome('chromedriver', options=chrome_options)
    
  • 最后重新运行你原来的Bokeh绘图和导出代码,就能成功保存SVG文件了。

内容的提问来源于stack exchange,提问作者Jaja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 09:52:05