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

使用dataframe_image导出DataFrame时遇subprocess.CalledProcessError错误

问题:使用dataframe_image导出DataFrame时触发subprocess.CalledProcessError

场景说明

用dataframe_image做导出已经两年,今天运行dfi.export(设置了隐藏索引轴、指定字号和dpi)时突然报错,推测可能是Chrome近期更新或者generate_image_from_html的参数问题导致。

完整报错信息

Traceback (most recent call last):
  File "C:\Users\david.clark\REPORT_TrendQuality\venv\lib\site-packages\dataframe_image\_screenshot.py", line 142, in take_screenshot
    self.generate_image_from_html(args)
  File "C:\Users\david.clark\REPORT_TrendQuality\venv\lib\site-packages\dataframe_image\_screenshot.py", line 150, in generate_image_from_html
    subprocess.run(executable=self.chrome_path, args=args, capture_output=True, check=True)
  File "C:\Users\david.clark\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['--enable-logging', '--disable-gpu', '--headless', '--crash-dumps-dir=C:\\Users\\DAVID~1.CLA\\AppData\\Local\\Temp\\tmpw370ybdw', '--force-device-scale-factor=2.0', '--window-size=1400,900', '--hide-scrollbars', '--screenshot=C:\\Users\\DAVID~1.CLA\\AppData\\Local\\Temp\\tmpw370ybdw\\temp.png', 'C:\\Users\\DAVID~1.CLA\\AppData\\Local\\Temp\\tmpw370ybdw\\temp.html']' returned non-zero exit status 21.

执行的代码

metrics_df = metrics_df.style.hide(axis="index")
dfi.export(metrics_df, '{}_{}_{}_trend_quality_table_1.png'.format(row['CDAP Env.'], row['Patient ID'], row['Cordella ID']),
           fontsize=10, dpi=200)

预期效果

在工作目录生成命名格式为a_b_c_trend_quality_table_1.png的DataFrame图片(a、b、c分别对应实际的CDAP环境、患者ID、Cordella ID)。

解决方法(感谢Andrews)

在dfi.export中添加table_conversion参数,将默认的chrome切换为matplotlib即可正常运行,修改后的代码如下:

metrics_df = metrics_df.style.hide(axis="index")
dfi.export(metrics_df, '{}_{}_{}_trend_quality_table_1.png'.format(row['CDAP Env.'], row['Patient ID'], row['Cordella ID']),
           fontsize=10, dpi=200, table_conversion='matplotlib')

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 02:36:11