python 语法错误:不是PNG文件

x7rlezfr  于 2023-03-21  发布在  Python
关注(0)|答案(1)|浏览(448)

很长一段时间以来我一直在用

dfi.export(df1, "test.png")

将类型为pandas.io.formats.style.Styler的dataframe styler(df1)导出到. png。
今天我得到以下错误:

Traceback (most recent call last):

  File ~\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py:3369 in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  Input In [48] in <cell line: 1>
    dfi.export(df1, "ice_cotton_" + str(dashboard_date).split(" ")[0])

  File ~\Anaconda3\lib\site-packages\dataframe_image\_pandas_accessor.py:48 in export
    return _export(

  File ~\Anaconda3\lib\site-packages\dataframe_image\_pandas_accessor.py:117 in _export
    img_str = converter(html)

  File ~\Anaconda3\lib\site-packages\dataframe_image\_screenshot.py:188 in run
    img = self.take_screenshot()

  File ~\Anaconda3\lib\site-packages\dataframe_image\_screenshot.py:140 in take_screenshot
    img = mimage.imread(buffer)

  File ~\Anaconda3\lib\site-packages\matplotlib\image.py:1560 in imread
    with img_open(fname) as image:

  File ~\Anaconda3\lib\site-packages\PIL\ImageFile.py:112 in __init__
    self._open()

  File ~\Anaconda3\lib\site-packages\PIL\PngImagePlugin.py:676 in _open
    raise SyntaxError("not a PNG file")

  File <string>
SyntaxError: not a PNG file

我该怎么解决这个问题?

nhaq1z21

nhaq1z211#

这是一组可能的解决方案,只有最后一个对我有效:

  1. matplotlib的早期版本,例如3.4.3
    1.使用后端,例如'mpl.use(' ps ')'
  2. dataframe-image的早期版本(测试0.1.3、0.1.2和0.1.0)
  3. table_conversion,例如dfi.export(table,table_conversion='firefox'):这不会给出错误,但格式丢失
    1.上一版本的Chrome(即1月27日;109.0.5414.119):这个管用!

相关问题