Home > Software engineering >  Error exporting styled dataframes to image, "SyntaxError: not a PNG file" using dataframe_
Error exporting styled dataframes to image, "SyntaxError: not a PNG file" using dataframe_

Time:01-19

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

CodePudding user response:

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

CodePudding user response:

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.

  • Related