dexplo / dataframe_image

A python package for embedding pandas DataFrames as images into pdf and markdown documents
https://dexplo.org/dataframe_image
MIT License
282 stars 41 forks source link

CalledProcessError (returns exit status 64) #105

Closed JulianneDavid closed 1 year ago

JulianneDavid commented 1 year ago

Hi, I'm having trouble saving a dataframe image with table_conversion='chrome'.

I originally had an issue that was solved by following the advice to upgrade to a newer version of dataframe_image, and after upgrading with pip I now have Version: 0.1.14.

However, now I have a CalledProcessError and I'm wondering if you've seen this before or have advice on how to solve it. See code and error below. Thanks, Julianne

sample code:

import dataframe_image as dfi
import numpy as np
import pandas as pd
df = pd.DataFrame(
    np.random.randn(5, 5), columns=['col{}'.format(i) for i in range(5)]
)
dfi.export(df, 'test_df.png', table_conversion = 'chrome')

throws the following error:

---------------------------------------------------------------------------
---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
/tmp/ipykernel_3364645/3115311874.py in <module>
      5     np.random.randn(5, 5), columns=['col{}'.format(i) for i in range(5)]
      6 )
----> 7 dfi.export(df, 'test_df.png', table_conversion = 'chrome')

/tools/miniconda3/envs/test2/lib/python3.7/site-packages/dataframe_image/_pandas_accessor.py in export(obj, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path, dpi)
     47 ):
     48     return _export(
---> 49         obj, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path, dpi
     50     )
     51 

/tools/miniconda3/envs/test2/lib/python3.7/site-packages/dataframe_image/_pandas_accessor.py in _export(obj, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path, dpi)
    141         html = obj.to_html(max_rows=max_rows, max_cols=max_cols, notebook=True)
    142 
--> 143     img_str = converter(html)
    144 
    145     try:

/tools/miniconda3/envs/test2/lib/python3.7/site-packages/dataframe_image/_screenshot.py in run(self, html)
    204     def run(self, html):
    205         self.html = html
--> 206         img = self.take_screenshot()
    207         img_str = self.finalize_image(img)
    208         return img_str

/tools/miniconda3/envs/test2/lib/python3.7/site-packages/dataframe_image/_screenshot.py in take_screenshot(self, ss_width, ss_height)
    140             ]
    141 
--> 142             self.generate_image_from_html(args)
    143             with open(temp_img, "rb") as f:
    144                 bio = io.BytesIO(f.read())

/tools/miniconda3/envs/test2/lib/python3.7/site-packages/dataframe_image/_screenshot.py in generate_image_from_html(self, args)
    149         # print(self.chrome_path)
    150         subprocess.run(
--> 151             executable=self.chrome_path, args=args, capture_output=True, check=True
    152         )
    153 

/tools/miniconda3/envs/test2/lib/python3.7/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    510         if check and retcode:
    511             raise CalledProcessError(retcode, process.args,
--> 512                                      output=stdout, stderr=stderr)
    513     return CompletedProcess(process.args, retcode, stdout, stderr)
    514 

CalledProcessError: Command '['--enable-logging', '--disable-gpu', '--headless', '--crash-dumps-dir=/tmp/tmpxk6sf4w9', '--force-device-scale-factor=1', '--window-size=1400,900', '--hide-scrollbars', '--screenshot=/tmp/tmpxk6sf4w9/temp.png', '/tmp/tmpxk6sf4w9/temp.html']' returned non-zero exit status 64.
JulianneDavid commented 1 year ago

Actually, I am getting the same error even without the table_conversion='chrome' option - input and error are the same regardless. Sorry for the confusion above!

PaleNeutron commented 1 year ago

Can you check your chrome version? I think it is some problem based on chrome.

And you could install another “chromium based browser” such as chromium, edge and export image with dfi.export(df, 'test_df.png', chrome_path='your/edge/binary/path')

JulianneDavid commented 1 year ago

Thanks for your help here! I wasn't able to install edge due to problems solving the environment, but I just tried chromium, version 696693 from conda. I'm now getting a different exit status, 127. If you think it might make a substantial difference, I can start a new environment and try to get edge installed.

sample code:

import dataframe_image as dfi
import numpy as np
import pandas as pd
df = pd.DataFrame(
    np.random.randn(5, 5), columns=['col{}'.format(i) for i in range(5)]
)
dfi.export(
    df, 'test_df.png', 
    table_conversion='chrome',
    chrome_path='/tools/miniconda3/envs/test2/bin/chromium/chrome'
)

which raises the error:

---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
/tmp/ipykernel_3397822/201340352.py in <module>
      8     df, 'test_df.png',
      9     table_conversion='chrome',
---> 10     chrome_path='/tools/miniconda3/envs/test2/bin/chromium/chrome'
     11 )

/tools/miniconda3/envs/test2/lib/python3.7/site-packages/dataframe_image/_pandas_accessor.py in export(obj, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path, dpi)
     47 ):
     48     return _export(
---> 49         obj, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path, dpi
     50     )
     51 

/tools/miniconda3/envs/test2/lib/python3.7/site-packages/dataframe_image/_pandas_accessor.py in _export(obj, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path, dpi)
    141         html = obj.to_html(max_rows=max_rows, max_cols=max_cols, notebook=True)
    142 
--> 143     img_str = converter(html)
    144 
    145     try:

/tools/miniconda3/envs/test2/lib/python3.7/site-packages/dataframe_image/_screenshot.py in run(self, html)
    204     def run(self, html):
    205         self.html = html
--> 206         img = self.take_screenshot()
    207         img_str = self.finalize_image(img)
    208         return img_str

/tools/miniconda3/envs/test2/lib/python3.7/site-packages/dataframe_image/_screenshot.py in take_screenshot(self, ss_width, ss_height)
    140             ]
    141 
--> 142             self.generate_image_from_html(args)
    143             with open(temp_img, "rb") as f:
    144                 bio = io.BytesIO(f.read())

/tools/miniconda3/envs/test2/lib/python3.7/site-packages/dataframe_image/_screenshot.py in generate_image_from_html(self, args)
    149         # print(self.chrome_path)
    150         subprocess.run(
--> 151             executable=self.chrome_path, args=args, capture_output=True, check=True
    152         )
    153 

/tools/miniconda3/envs/test2/lib/python3.7/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    510         if check and retcode:
    511             raise CalledProcessError(retcode, process.args,
--> 512                                      output=stdout, stderr=stderr)
    513     return CompletedProcess(process.args, retcode, stdout, stderr)
    514 

CalledProcessError: Command '['--enable-logging', '--disable-gpu', '--headless', '--crash-dumps-dir=/tmp/tmp4keujnwq', '--force-device-scale-factor=1', '--window-size=1400,900', '--hide-scrollbars', '--screenshot=/tmp/tmp4keujnwq/temp.png', '/tmp/tmp4keujnwq/temp.html']' returned non-zero exit status 127.
PaleNeutron commented 1 year ago

I think the latest chromium is 118 and I found that anaconda version is 3 years ago. https://anaconda.org/esss/chromium

Please install chromium from your package manager, for debian based distro try sudo apt install chromium-browser.

JulianneDavid commented 1 year ago

So, I'm still getting the error - now with exit code 2.

The version I have (non-conda) is Chromium 118.0.5993.70 snap, and here are the inputs/output:

import dataframe_image as dfi
import numpy as np
import pandas as pd
df = pd.DataFrame(
    np.random.randn(5, 5), columns=['col{}'.format(i) for i in range(5)]
)
dfi.export(
    df, 'test_df.png', 
    table_conversion='chrome',
    chrome_path='/usr/bin/chromium-browser'
)
---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
/tmp/ipykernel_3397822/1933507396.py in <module>
      8     df, 'test_df.png',
      9     table_conversion='chrome',
---> 10     chrome_path='/usr/bin/chromium-browser'
     11 )

/tools/miniconda3/envs/test2/lib/python3.7/site-packages/dataframe_image/_pandas_accessor.py in export(obj, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path, dpi)
     47 ):
     48     return _export(
---> 49         obj, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path, dpi
     50     )
     51 

/tools/miniconda3/envs/test2/lib/python3.7/site-packages/dataframe_image/_pandas_accessor.py in _export(obj, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path, dpi)
    141         html = obj.to_html(max_rows=max_rows, max_cols=max_cols, notebook=True)
    142 
--> 143     img_str = converter(html)
    144 
    145     try:

/tools/miniconda3/envs/test2/lib/python3.7/site-packages/dataframe_image/_screenshot.py in run(self, html)
    204     def run(self, html):
    205         self.html = html
--> 206         img = self.take_screenshot()
    207         img_str = self.finalize_image(img)
    208         return img_str

/tools/miniconda3/envs/test2/lib/python3.7/site-packages/dataframe_image/_screenshot.py in take_screenshot(self, ss_width, ss_height)
    140             ]
    141 
--> 142             self.generate_image_from_html(args)
    143             with open(temp_img, "rb") as f:
    144                 bio = io.BytesIO(f.read())

/tools/miniconda3/envs/test2/lib/python3.7/site-packages/dataframe_image/_screenshot.py in generate_image_from_html(self, args)
    149         # print(self.chrome_path)
    150         subprocess.run(
--> 151             executable=self.chrome_path, args=args, capture_output=True, check=True
    152         )
    153 

/tools/miniconda3/envs/test2/lib/python3.7/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    510         if check and retcode:
    511             raise CalledProcessError(retcode, process.args,
--> 512                                      output=stdout, stderr=stderr)
    513     return CompletedProcess(process.args, retcode, stdout, stderr)
    514 

CalledProcessError: Command '['--enable-logging', '--disable-gpu', '--headless', '--crash-dumps-dir=/tmp/tmp85bkbz23', '--force-device-scale-factor=1', '--window-size=1400,900', '--hide-scrollbars', '--screenshot=/tmp/tmp85bkbz23/temp.png', '/tmp/tmp85bkbz23/temp.html']' returned non-zero exit status 2.
RRighart commented 1 year ago

Similar error here, CalledProcessError: Command '['--enable-logging', '--disable-gpu', '--headless', '--crash-dumps-dir=/home/administrateur/tmp8jv7ju_h', '--force-device-scale-factor=1', '--window-size=1400,900', '--hide-scrollbars', '--screenshot=/home/administrateur/tmp8jv7ju_h/temp.png', '/home/administrateur/tmp8jv7ju_h/temp.html']' returned non-zero exit status 64.. I am running Jupyter Notebook in Mozilla Firefox.

PaleNeutron commented 1 year ago

@JulianneDavid See here '--screenshot=/tmp/tmp85bkbz23/temp.png', '/tmp/tmp85bkbz23/temp.html', dfi 0.1.4 use system temp dir which is not accessable with snap version chromium/chrome.

I moved temp directory under home directory in latest version 0.2.2. Just upgrade and I think it will work.

JulianneDavid commented 1 year ago

This worked for me! I now am getting now errors with: chromium 118 dataframe_image 0.2.2

Thanks very much for helping me get this to work.