dataframe_image
dataframe_image copied to clipboard
Works great on local machine, but doesn't work on Google Colab
Hi, thank you for library. It works great on the local machine, but I moved my script to Google Colab. Step 1: install all libraries
!pip install selenium
!apt-get update # to update ubuntu to correctly run apt install
!apt install chromium-chromedriver
sys.path.insert(0,'/usr/lib/chromium-browser/chromedriver')
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
!pip install dataframe_image
import dataframe_image as dfi
Step 2: export df using library
df.dfi.export('df.png')
And got error: OSError: read past end of file
Step 3: export df using library with specifying chrome webdriver path
df.dfi.export('df.png', chrome_path='/usr/lib/chromium-browser/chromedriver')
This process goes for ever. On local machine it takes a few second with same dataframe.
Please, ask any details if needed
Same error: Here is the trace log
<ipython-input-109-5e8650e8a499> in disp_to_file(df, path)
----> 5 df.dfi.export('df.png')
/usr/local/lib/python3.7/dist-packages/dataframe_image/_pandas_accessor.py in export(self, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path)
17 table_conversion='chrome', chrome_path=None):
18 return _export(self._df, filename, fontsize, max_rows, max_cols,
---> 19 table_conversion, chrome_path)
20
21
/usr/local/lib/python3.7/dist-packages/dataframe_image/_pandas_accessor.py in _export(obj, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path)
71 html = obj.to_html(max_rows=max_rows, max_cols=max_cols, notebook=True)
72
---> 73 img_str = converter(html)
74
75 if isinstance(filename, str):
/usr/local/lib/python3.7/dist-packages/dataframe_image/_screenshot.py in run(self, html)
165 def run(self, html):
166 self.html = self.css + html
--> 167 img = self.take_screenshot()
168 img_str = self.finalize_image(img)
169 return img_str
/usr/local/lib/python3.7/dist-packages/dataframe_image/_screenshot.py in take_screenshot(self)
117
118 buffer = io.BytesIO(img_bytes)
--> 119 img = mimage.imread(buffer)
120 return self.possibly_enlarge(img)
121
/usr/local/lib/python3.7/dist-packages/matplotlib/image.py in imread(fname, format)
1473 return _png.read_png(fd)
1474 with cbook.open_file_cm(fname, "rb") as file:
-> 1475 return _png.read_png(file)
1476
1477
OSError: read past end of file
I am getting the same error on Google Colab. I installed chrome there using the following commands:
! wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -O google-chrome-stable_current_amd64.deb
! apt-get install -y -qq ./google-chrome-stable_current_amd64.deb
dfi.export(df_styled, filename)
returns the following error for me:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
[<ipython-input-48-84798923a74e>](https://localhost:8080/#) in <module>()
11 "ارزش تومان": "{:,.0f}"
12 }) # Format columns
---> 13 dfi.export(df_styled, filename)
4 frames
[/usr/local/lib/python3.7/dist-packages/matplotlib/image.py](https://localhost:8080/#) in imread(fname, format)
1473 return _png.read_png(fd)
1474 with cbook.open_file_cm(fname, "rb") as file:
-> 1475 return _png.read_png(file)
1476
1477
OSError: read past end of file
Hello! Have anyone had updates on this problem? It doesn't work for me in G. Colab either.
I'll take a look at it asap
In Google Colab
A Known Issue: When using dataframe_image with Google Colab, you can not use default Chrome convert method. You can set table_conversion
parameter to 'selenium'
and it will call Firefox
driver to convert the DataFrames to images.
note: you have to install dependencies before use it:
!apt install firefox firefox-geckodriver
!pip install dataframe_image selenium
...
df.dfi.export('df.png', table_conversion='selenium')