Error exporting styled dataframes to image, "SyntaxError: not a PNG file" using dataframe_image

Question:

I’ve been using dataframe_image for a while and have had great results so far. Last week, out of a sudden, all my code containing the method dfi.export() stopped working with this error as an output

raise SyntaxError("not a PNG file")

File <string>
SyntaxError: not a PNG file

I can export the images passing the argument table_conversion='matplotlib' but they do not come out styled…

This is my code:

now = str(datetime.now())
filename = ("Extracciones-"+now[0:10]+".png")

df_styled = DATAFINAL.reset_index(drop=True).style.apply(highlight_rows, axis=1)

dfi.export(df_styled, filename,max_rows=-1)

IMAGEN = Image.open(filename)
IMAGEN.show()

Any clues on why this just suddenly stopped working?
Or any ideas to export dataframes as images (not using html)?

These were the outputs i used to get:
fully styled dataframe images

and this is the only thing I can get right now

Thank you in advance

Asked By: Agustin Gonzalez

||

Answers:

I had the same issue, and we finally figured it out; looks like the new release of dataframe_image on 1/14 broke something on the previous version.
We upgraded the package and the issue was resolved.

pip install -u dataframe_image
Answered By: Abe

dataframe_image has a dependency on Chrome, and a recent Chrome update (possibly v109 on 2013-01-10) broke dataframe_image. v0.1.5 was released on 2023-01-14 to fix this.

pip install --upgrade dataframe_image
pip show dataframe_image

The version should now be v0.1.5 or later, which should resolve the problem.


Some users have reported still having the error even after upgrading. This could be due to upgrading the package in the wrong directory (due to multiple installations of python, pip, virtual envs, etc). The reliable way to check the actual version of dataframe_image that the code is using, is to add this debugging code to the top of your python code:

import pandas as pd
import dataframe_image as dfi
from importlib.metadata import version

print(version('dataframe_image'))

df = pd.DataFrame({'x':[1,2]})
dfi.export(df, 'out.png')

exit()

Also check chrome://version/ in your Chrome browser.

Answered By: wisbucky

I fixed this issue.

It was related to resources that are busy in the background and chrome can’t use these resources.

https://github.com/dexplo/dataframe_image/pull/70

please update the library to version v0.1.5

you can do it via pip :

python -m pip install --upgrade dataframe-image

Good luck.

Answered By: ItamarShalev
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.