Problem with DataFrame_Image No such file or directory
AleelA190 opened this issue ยท 73 comments
When I try to save a dataframe with styler in a png, I have this error: "FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmph0pszm_j/temp.png'".
What is very strange is that yesterday it worked correctly for me and today it gives me that error for all the scripts which create a png from a dataframe. The specific problem is when I want to create the png image of a dataframe I get that error that is generated because the library tries to create a random temporary folder with an image called temp.png inside and when the library tries to open this temporary file, the library didn't find it.
How can I solve it?
same issue
same Issue
Same issue.
Maybe, the size of the image will make the error.
I treid to reduce the rows of dataframe and succeed in generating the image, but it's not a real solution.
same Issue, dataframe-image 0.1.5
==========found some problem============
dataframe_image._screenshot.py.Screenshot():
take_screenshot():
...
return self.possibly_enlarge(img) ------------------- A
possibly_enlarge():
...
# must be all white for 30 pixels in a row to trigger stop
if enlarge:
return self.take_screenshot() --------------- B
problem: A<->B loop call
========local fix==============
dataframe_image._screenshot.py:146 [possibly_enlarge()]
# must be all white for 30 pixels in a row to trigger stop
if all_white_vert[-30:].sum() != 30: --------------- line 146 old
self.ss_width = int(self.ss_width * 1.5)
enlarge = True
fix: edit 30 to 14(the fit num that my code debug get)
# must be all white for 30 pixels in a row to trigger stop
if all_white_vert[-14:].sum() != 14: --------------- line 146 new
self.ss_width = int(self.ss_width * 1.5)
enlarge = True
then run success!
Same issue
Same issue
Same issue
Same issue
I have the same issue, it looks like it was related to google chrome update. Right now a workaround is to add table_conversion='matplotlib' as it normally uses chrome as table conversion. But for me all the table formats were lost with this workaround.
Same issue.
Same issue
same issue
same issue
same issue dfi.export(df, "table.png", table_conversion='matplotlib')
works for the moment
same issue
same issue
Hi.
Here is the fix.
I followed the idea from @Neo-Luo which is documented here: https://developer.chrome.com/articles/new-headless/
Go to the file _screenshot.py
and change "--headless"
to "--headless=new"
The documenation from google says, that if you do not provide the "=new" then it will automatically use "=old"
I tried both suggestions by @benjaminmoritz, @ATcn and neither worked for me.
@gtianyi - in my case matplotlib is not as I need to keep the formatting intact.
local fix in _screenshot.py, line 157-158:
#if enlarge:
# return self.take_screenshot()
and use fontsize and dpi in export,
- fontsize that your table fit to image,
- dpi that enlarge the image to a readable size. dpi = 100 is 1, 150 is 1.5 and etc.
example:
dfi.export(df, "table.png", fontsize=8, dpi=150)
I tried both suggestions by @benjaminmoritz, @ATcn and neither worked for me.
@gtianyi - in my case matplotlib is not as I need to keep the formatting intact.
Same
Hi. Here is the fix. I followed the idea from @Neo-Luo which is documented here: https://developer.chrome.com/articles/new-headless/ Go to the file
_screenshot.py
and change"--headless"
to"--headless=new"
The documenation from google says, that if you do not provide the "=new" then it will automatically use "=old"
I tried, but unfortunately it doesn't work for some reason, although it understands argument "headless=old", if "headless=new" then doesn't take a screenshot (there is no file).
I modify _screenshot.py with selenium.webdriver.firefox and then convert temp.html to temp.png. I'm happy with it...
I noticed that on all devices, the screenshot began to be taken with a resolution of 800x600, and on all types of browsers with the chromium engine
That's strange. I use the newest version of chrome (111.0.5563.65) and don't forget to "restart" VSCode / python after editing the package. I have the packages in venv.
I just call dfi.export(df, filename, dpi=300)
I noticed that on all devices, the screenshot began to be taken with a resolution of 800x600, and on all types of browsers with the chromium engine
The same thing happened to me, so I decided to switch to Selenium instead. I also noticed a commend for the Chrome driver to take full-size screenshots. But doesn't know how to interact with it under headless mode.
I modify _screenshot.py with selenium.webdriver.firefox and then convert temp.html to temp.png. I'm happy with it...
Would you mind share your method pls?
I think the easiest way to fix this problem is like this:
As this problem is caused by the latest version of Chrome. New Headless Chrome was using the platform window size disregarding --window-size setting if it was larger than the active display work area. So when your dataframe shape is larger than 800*600, the code will run into Endless loop in possibly_enlarge and throw 'No such file or directory" Error.
you can use smaller 'fontsize' and greater 'dpi' to reshape your df display area, and then skip this problem.
for example:" fontsize=10 and dpi=100" caused this error but the following setting worked for my โdf' shape.
dfi.export(df, file_name, fontsize=3.8, dpi=800, table_conversion='chrome', chrome_path=None)
if your dataframe is bigger ,you can set fontsize smaller and set dpi greater untill it is successful.
@Neo-Luo I even tried fontsize=1, dpi=2000
and it did not work for me on a 4K Monitor.
My solution is working fine for me. Maybe others need to set ss._width = 1400
and ss_height = 900
to other values?
I work with the 0.1.5 Release. There has been a change in _screenshot.py which is not in the release
see here: 55ada23
This could also make a problem
Neo-Luo solution " fontsize=3.8, dpi=800, table_conversion='chrome', chrome_path=None" worked for me.
fontsize=3.8, dpi=800, table_conversion='chrome', chrome_path=None
Thanks @Neo-Luo . This helped overcome the issue.
I think the easiest way to fix this problem is like this:
As this problem is caused by the latest version of Chrome. New Headless Chrome was using the platform window size disregarding --window-size setting if it was larger than the active display work area. So when your dataframe shape is larger than 800*600, the code will run into Endless loop in possibly_enlarge and throw 'No such file or directory" Error.
you can use smaller 'fontsize' and greater 'dpi' to reshape your df display area, and then skip this problem. for example:" fontsize=10 and dpi=100" caused this error but the following setting worked for my โdf' shape.
dfi.export(df, file_name, fontsize=3.8, dpi=800, table_conversion='chrome', chrome_path=None)
if your dataframe is bigger ,you can set fontsize smaller and set dpi greater untill it is successful.
this works for me. Thank you very much!
Neo-Luo's workaround worked for me. I did simplify it a little by removing table_conversion='chrome', chrome_path=None
since those were already the default values. And increase fontsize
from 3.8 to 4 to be a round number.
dfi.export(df, file_name, fontsize=4, dpi=800)
Would it be helpful to modify the dataframe_image
code to try fontsize=4, dpi=800
if the default fails? This might make dfi.export()
work successfully for most cases without having all users change their code everywhere they call dfi.export()
Example (untested) pseudocode for https://github.com/dexplo/dataframe_image/blob/master/dataframe_image/_pandas_accessor.py
def export(...):
try:
_export(...)
except:
_export(..., fontsize=4, dpi=800)
I tried both suggestions by @benjaminmoritz, @ATcn and neither worked for me.
@gtianyi - in my case matplotlib is not as I need to keep the formatting intact.
the deep reason caused is a loop call between two function of the package,
I didnt pay more time to dig it deeply, just debug the key code, then edit condition value and pass the it.
mine is just one inst, not a common solve
Google collab solution
Hey,
I solved my problem by making small tweaks to the script shared by @waterbear1996
If your case is similar below, I share the solution.
1ยบ Select the code below and completely replace the _screenshot.py
Open the _screenshot.py:
/usr/local/lib/python3.9/dist-packages/dataframe_image/_screenshot.py
Copy the code below and replace:
import base64
import io
import platform
import shutil
import subprocess
from pathlib import Path
from tempfile import TemporaryDirectory
import numpy as np
from matplotlib import image as mimage
from .pd_html import styler2html
#Add the following
import selenium.webdriver
import selenium.common
import os
options = selenium.webdriver.firefox.options.Options()
options.add_argument("--headless")
###
def get_system():
system = platform.system().lower()
if system in ["darwin", "linux", "windows"]:
return system
else:
raise OSError(f"Unsupported OS - {system}")
def get_chrome_path(chrome_path=None):
system = get_system()
if chrome_path:
return chrome_path
if system == "darwin":
paths = [
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"/Applications/Brave Browser.app/Contents/MacOS/Brave Browser",
]
for path in paths:
if Path(path).exists():
return path
raise OSError("Chrome executable not able to be found on your machine")
elif system == "linux":
paths = [
None,
"/usr/local/sbin",
"/usr/local/bin",
"/usr/sbin",
"/usr/bin",
"/sbin",
"/bin",
"/opt/google/chrome",
]
commands = [
"google-chrome",
"chrome",
"chromium",
"chromium-browser",
"brave-browser",
]
for path in paths:
for cmd in commands:
chrome_path = shutil.which(cmd, path=path)
if chrome_path:
return chrome_path
raise OSError("Chrome executable not able to be found on your machine")
elif system == "windows":
import winreg
locs = [
r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe",
r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\brave.exe",
]
for loc in locs:
handle = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, loc)
num_values = winreg.QueryInfoKey(handle)[1]
if num_values > 0:
return winreg.EnumValue(handle, 0)[1]
raise OSError("Cannot find chrome.exe on your windows machine")
class Screenshot:
def __init__(
self,
center_df=True,
max_rows=None,
max_cols=None,
chrome_path=None,
fontsize=18,
encode_base64=True,
limit_crop=True,
device_scale_factor=1
):
self.center_df = center_df
self.max_rows = max_rows
self.max_cols = max_cols
self.ss_width = 1400
self.ss_height = 900
self.chrome_path = get_chrome_path(chrome_path)
self.css = self.get_css(fontsize)
self.encode_base64 = encode_base64
self.limit_crop = limit_crop
self.device_scale_factor = device_scale_factor
def get_css(self, fontsize):
mod_dir = Path(__file__).resolve().parent
css_file = mod_dir / "static" / "style.css"
with open(css_file) as f:
css = "<style>" + f.read() + "</style>"
justify = "center" if self.center_df else "left"
css = css.format(fontsize=fontsize, justify=justify)
return css
def take_screenshot(self):
temp_dir = TemporaryDirectory()
temp_html = Path(temp_dir.name) / "temp.html"
temp_img = Path(temp_dir.name) / "temp.png"
with open(temp_html, "w", encoding="utf-8") as f:
f.write(self.html)
args = [
"--enable-logging",
"--disable-gpu",
"--headless",
"--no-sandbox",
"--crash-dumps-dir=/tmp",
f"--force-device-scale-factor={self.device_scale_factor}",
]
# if self.ss_width and self.ss_height:
# args.append(f"--window-size={self.ss_width},{self.ss_height}")
args += [
"--hide-scrollbars",
f"--screenshot={str(temp_img)}",
str(temp_html),
]
with selenium.webdriver.Firefox(options=options) as driver:
shutil.copy(temp_html,"/tmp") # move file from tmp to your desired working folder
driver.get('file:///tmp/temp.html') # selenium will do the rest
required_width = driver.execute_script('return document.body.parentNode.scrollWidth')
required_height = driver.execute_script('return document.body.parentNode.scrollHeight')
driver.set_window_size(required_width+150,required_height+90)
driver.save_screenshot(temp_img)
# subprocess.run(executable=self.chrome_path, args=args)
with open(temp_img, "rb") as f:
img_bytes = f.read()
buffer = io.BytesIO(img_bytes)
img = mimage.imread(buffer)
return self.possibly_enlarge(img)
def possibly_enlarge(self, img):
enlarge = False
img2d = img.mean(axis=2) == 1
all_white_vert = img2d.all(axis=0)
# must be all white for 30 pixels in a row to trigger stop
if all_white_vert[-5:].sum() != 5:
self.ss_width = int(self.ss_width * 1.5)
enlarge = True
all_white_horiz = img2d.all(axis=1)
if all_white_horiz[-5:].sum() != 5:
self.ss_height = int(self.ss_height * 1.5)
enlarge = True
if enlarge:
return self.take_screenshot()
return self.crop(img, all_white_vert, all_white_horiz)
def crop(self, img, all_white_vert, all_white_horiz):
diff_vert = np.diff(all_white_vert)
left = diff_vert.argmax()
right = -diff_vert[::-1].argmax()
if self.limit_crop:
max_crop = int(img.shape[1] * 0.15)
left = min(left, max_crop)
right = max(right, -max_crop)
diff_horiz = np.diff(all_white_horiz)
top = diff_horiz.argmax()
bottom = -diff_horiz[::-1].argmax()
new_img = img[top:bottom, left:right]
return new_img
def finalize_image(self, img):
buffer = io.BytesIO()
mimage.imsave(buffer, img)
img_str = buffer.getvalue()
if self.encode_base64:
img_str = base64.b64encode(img_str).decode()
return img_str
def run(self, html):
self.html = self.css + html
img = self.take_screenshot()
img_str = self.finalize_image(img)
return img_str
def repr_png_wrapper(self):
from pandas.io.formats.style import Styler
ss = self
def _repr_png_(self):
if isinstance(self, Styler):
html = styler2html(self)
else:
html = self.to_html(
max_rows=ss.max_rows, max_cols=ss.max_cols, notebook=True
)
return ss.run(html)
return _repr_png_
def make_repr_png(center_df=True, max_rows=30, max_cols=10, chrome_path=None):
"""
Used to create a _repr_png_ method for DataFrames and Styler objects
so that nbconvert can use it to create images directly when
executing the notebook before conversion to pdf/markdown.
Parameters
----------
center_df : bool, default True
Choose whether to center the DataFrames or not in the image. By
default, this is True, though in Jupyter Notebooks, they are
left-aligned. Use False to make left-aligned.
max_rows : int, default 30
Maximum number of rows to output from DataFrame. This is forwarded to
the `to_html` DataFrame method.
max_cols : int, default 10
Maximum number of columns to output from DataFrame. This is forwarded
to the `to_html` DataFrame method.
chrome_path : str, default None
Path to your machine's chrome executable. When `None`, it is
automatically found. Use this when chrome is not automatically found.
"""
ss = Screenshot(center_df, max_rows, max_cols, chrome_path)
return ss.repr_png_wrapper()
Remembering that to use this code it is necessary to install selenium.webdriver
after performing the step by step, restart the environment without installing the libraries again.
Hello, everyone. I have published a new release which should resolve current problem. Can you update to latest version and check if it works?
BTW, it supports Google colab now.
Hello, everyone. I have published a new release which should resolve current problem. Can you update to latest version and check if it works?
BTW, it supports Google colab now.
Hi @PaleNeutron , confirm that it works on my end. Thanks for the quick fix!!
@PaleNeutron Thx for ur contribution. I try the latest version, but it doesnt work for me. It just converts several lines in the top of the dataframe. The rest of the dataframe cannot be exported correctly.
@hdliu1997 I think your problem is not related to this issue. Please open a new issue and provide full example code to reproduce the problem.
@PaleNeutron I try the latest version, it has a new error:
{CalledProcessError}Command '['--enable-logging', '--disable-gpu', '--headless=new', '--crash-dumps-dir=/tmp', '--force-device-scale-factor=1', '--window-size=1400,900', '--hide-scrollbars', '--screenshot=C:\\Users\\dingm\\AppData\\Local\\Temp\\tmp_2r5igrl\\temp.png', 'C:\\Users\\dingm\\AppData\\Local\\Temp\\tmp_2r5igrl\\temp.html']' returned non-zero exit status 21.
I run it on Windows 11.
@KevinMyDing, the latest version from pypi not github. Github version is not stable.
pip install dataframe_image==0.1.7
@hdliu1997 same issue. I tried the latest version 0.1.7, but it did not work for me too. Actually, the warning disappeared, but I obtained a wrong dataframe image. The image is just a white line.
The code dfi.export(df, name, fontsize=3.8, dpi=800, table_conversion='chrome', chrome_path=None) works well. But this gives me an ugly dataframe with fat table line, which is not the same with the dataframe in the cell. @PaleNeutron .
@hdliu1997 same issue. I tried the latest version 0.1.7, but it did not work for me too. Actually, the warning disappeared, but I obtained a wrong dataframe image. The image is just a white line. The code dfi.export(df, name, fontsize=3.8, dpi=800, table_conversion='chrome', chrome_path=None) works well. But this gives me an ugly dataframe with fat table line, which is not the same with the dataframe in the cell. @PaleNeutron .
Ur advice works well for me too. It's a great alternative before this issue is fixed lol
@hdliu1997 Was your HTML file generated correctly๏ผ There may be an issue with geckodriver...
@hdliu1997 same issue. I tried the latest version 0.1.7, but it did not work for me too. Actually, the warning disappeared, but I obtained a wrong dataframe image. The image is just a white line. The code dfi.export(df, name, fontsize=3.8, dpi=800, table_conversion='chrome', chrome_path=None) works well. But this gives me an ugly dataframe with fat table line, which is not the same with the dataframe in the cell. @PaleNeutron .
same issue.
the tmp.html and tmp.png is working.
Hi @PaleNeutron for me the error no longer appears, but now the problem has changed and reaches another way, see:
Before the problem, when I used:
dfi.export(df, name_file + ".png")
I was able to print 70 lines without any problem. After the problem, I had to adjust to keep the result at least similar:
dfi.export(df, name_file + ".png", fontsize=3.8, dpi=800, table_conversion='chrome', chrome_path=None)
Now (0.1.7 version) going back to the original, I tried to run it and got this result (notice it's cut off with missing lines):
dfi.export(df, name_file + ".png")
For me the error no longer appears, but now the problem has changed and reaches another way, see:
Before the problem, when I used:
dfi.export(df, name_file + ".png")
I was able to print 70 lines without any problem. After the problem, I had to adjust to keep the result at least similar:
dfi.export(df, name_file + ".png", fontsize=3.8, dpi=800, table_conversion='chrome', chrome_path=None)
Now (0.1.7 version) going back to the original, I tried to run it and got this result (notice it's cut off with missing lines):
dfi.export(df, name_file + ".png")
I am having the same issue. I no longer get the error, but my tables are getting cut off early.
@fredericomattos @calvin5walters , this is a known issue. Latest version chrome will not accept cli argument window-size so you can not get full image with chrome.
Two solutions:
dfi.export(df, name_file + ".png", fontsize=3.8, dpi=800, table_conversion='chrome', chrome_path=None)
will still work- use selenium with Firefox :
!apt install firefox firefox-geckodriver
!pip install dataframe_image selenium
df.dfi.export('df.png', table_conversion="selenium", max_rows=-1)
There is a third solution!
My first solution is also not working for me anymore.
The bug regarding window-size
has been addressed at Google Developers:
https://support.google.com/chrome/thread/206429303/chrome-headless-screenshot-not-respecting-window-size-anymore?hl=en
And has been fixed by them in the Release "113.0.5656.0"
https://bugs.chromium.org/p/chromium/issues/detail?id=1424464
So it should be in the Beta-Release in the next weeks
In the meantime you can install Google Chrome Developer Version. It is the Release "113.0.5656.0"
https://www.google.com/intl/de/chrome/dev/
Then set the chrome_path and it works for me with pip install dataframe-image==0.1.7
dfi.export(df, 'filename_png, dpi=300, chrome_path='C:\Program Files\Google\Chrome Dev\Application\chrome.exe')
Thank you @PaleNeutron.
Proposed Solution 1.
dfi.export(df, name_file + ".png", fontsize=3.8, dpi=800, table_conversion='chrome', chrome_path=None, max_rows=-1)
is cutting all of my tables off at 68 rows
Proposed Solution 2.
When I run !apt install firefox firefox-geckodriver
I get the error:
The operation couldnโt be completed. Unable to locate a Java Runtime that supports apt.
Please visit http://www.java.com/ for information on installing Java.
After installing the Java file from the link, I get the same error.
Any help is appreciated!
Thanks Benjamin. @benjaminmoritz
After downloading the linked Google Chrome Developer Version (now "113.0.5668.0"), and running:
dfi.export(df, 'filename_png', dpi=300, max_rows=-1, chrome_path='/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev')
all of my tables are getting cut off at 29 rows.
Any help is appreciated. Thanks!
Proposed Solution 1.
dfi.export(df, name_file + ".png", fontsize=3.8, dpi=800, table_conversion='chrome', chrome_path=None, max_rows=-1)
is cutting all of my tables off at 68 rows
It is excepted. The latest version is a mitigation only. See release note:
https://github.com/dexplo/dataframe_image/releases/tag/v0.1.8
Proposed Solution 2. When I run
!apt install firefox firefox-geckodriver
I get the error:The operation couldnโt be completed. Unable to locate a Java Runtime that supports apt.
Please visit http://www.java.com/ for information on installing Java.After installing the Java file from the link, I get the same error. Any help is appreciated!
You should install following packages depends on your os, apt
is just for Debian-based distributions.
firefox firefox-geckodriver
Following the document carefully: https://selenium-python.readthedocs.io/installation.html#drivers
Proposed Solution 1.
dfi.export(df, name_file + ".png", fontsize=3.8, dpi=800, table_conversion='chrome', chrome_path=None, max_rows=-1)
is cutting all of my tables off at 68 rowsIt is excepted. The latest version is a mitigation only. See release note: https://github.com/dexplo/dataframe_image/releases/tag/v0.1.8
Proposed Solution 2. When I run
!apt install firefox firefox-geckodriver
I get the error:The operation couldnโt be completed. Unable to locate a Java Runtime that supports apt.
Please visit http://www.java.com/ for information on installing Java.After installing the Java file from the link, I get the same error. Any help is appreciated!
You should install following packages depends on your os,
apt
is just for Debian-based distributions.firefox firefox-geckodriver
Following the document carefully: https://selenium-python.readthedocs.io/installation.html#drivers
Hi,
I'm receiving a new error running dfi.export(df, file+".png") with v.0.1.8:
"Command '['--enable-logging', '--disable-gpu', '--headless=new', '--crash-dumps-dir=/tmp', '--force-device-scale-factor=1', '--window-size=1400,900', '--hide-scrollbars', '--screenshot=/tmp/tmpm1gw2k6t/temp.png', '/tmp/tmpm1gw2k6t/temp.html']' returned non-zero exit status 1."
@lovatoarthur, I need more information from your console to find out why Chrome failed.
There should be something like this:
[6013:6013:0323/021804.419849:ERROR:process_singleton_posix.cc(334)] Failed to create /home/runner/.config/google-chrome/SingletonLock: File exists (17)
[6057:6057:0100/000000.449195:ERROR:broker_posix.cc(43)] Invalid node channel message
[6058:6058:0323/021804.465607:ERROR:broker_posix.cc(43)] Invalid node channel message
@PaleNeutron
[887:887:0329/031559.176018:ERROR:zygote_host_impl_linux.cc(100)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
Maybe because I'm running as root?
@lovatoarthur , This is my mistake. I comment --no-sandbox
in code to test new headless mode. You colud search it in source code and uncomment it. I think everything will work.
@PaleNeutron got a different error after uncommenting --no-sandbox.
[473:495:0329/160138.866405:ERROR:bus.cc(399)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix") [473:495:0329/160138.892291:ERROR:bus.cc(399)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix") [473:495:0329/160138.892384:ERROR:bus.cc(399)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix") [473:621:0329/160139.078279:ERROR:object_proxy.cc(623)] Failed to call method: org.freedesktop.DBus.Properties.Get: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files [473:621:0329/160139.078906:ERROR:object_proxy.cc(623)] Failed to call method: org.freedesktop.UPower.GetDisplayDevice: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files [473:621:0329/160139.079814:ERROR:object_proxy.cc(623)] Failed to call method: org.freedesktop.UPower.EnumerateDevices: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files [0329/160139.500448:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2) [0329/160139.500632:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2) [0329/160139.589829:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2) [0329/160139.589928:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2) [0329/160139.664141:ERROR:nacl_helper_linux.cc(355)] NaCl helper process running without a sandbox! Most likely you need to configure your SUID sandbox correctly
subprocess.CalledProcessError: Command '['--enable-logging', '--disable-gpu', '--headless=new', '--no-sandbox', '--crash-dumps-dir=/tmp', '--force-device-scale-factor=1.99', '--window-size=1400,900', '--hide-scrollbars', '--screenshot=/tmp/tmp_ztjot6k/temp.png', '/tmp/tmp_ztjot6k/temp.html']' died with <Signals.SIGTRAP: 5>.
Any advices on how to fix it?
@lovatoarthur , Chrome is black magic, for me... Try --headless
instead of --headless=new
and I'm not shoul it will help.
I can only test it in my develop environment now, whatever argument I choose for chrome it will fail in github action environment.
My advice is, get rid of latest version Chrome and choose selenium+Firefox
.
Thanks Benjamin. @benjaminmoritz
After downloading the linked Google Chrome Developer Version (now "113.0.5668.0"), and running:
dfi.export(df, 'filename_png', dpi=300, max_rows=-1, chrome_path='/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev')
all of my tables are getting cut off at 29 rows. Any help is appreciated. Thanks!
Thats weird. After Google Chrome Dev updated from 113.0.5656.0
to 113.0.5668.0
automatically it isn't working for my any more as well...
@PaleNeutron thanks for the support.
I've been trying to work selenium+Firefox
, but some styles I'm applying with pandas are getting lost.
Not sure if it's related to my linux vm configuration, because on Windows they seem to work.
with chrome is apparently simple: just add , fontsize=3.8, dpi=300
after the definition of the .png file.
Thanks Benjamin. @benjaminmoritz
After downloading the linked Google Chrome Developer Version (now "113.0.5668.0"), and running:dfi.export(df, 'filename_png', dpi=300, max_rows=-1, chrome_path='/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev')
all of my tables are getting cut off at 29 rows. Any help is appreciated. Thanks!Thats weird. After Google Chrome Dev updated from
113.0.5656.0
to113.0.5668.0
automatically it isn't working for my any more as well...
Dang. Please let me know if this gets fixed again! Thanks Benjamin.
Hey team,
Thanks to this comment in another repo, I have found a temporary workaround. As suggested in the comment, I downloaded a portable version of Chrome v109 - googlechromeportable64_109.0.5414.120_online.paf from here: https://sourceforge.net/projects/portableapps/files/Google%20Chrome%20Portable/.
Then, I just have to amend my function to
styler.export_png(
str(filepath),
fontsize=16,
max_rows=200,
chrome_path="GoogleChromePortable64/App/Chrome-bin/chrome.exe",
)
BTW- I'm on dataframe-image==0.1.5
. I couldn't quite get the same behavior with the latest PyPI version (0.1.10).
@moshemoshe137 , Yes, dataframe-image==0.1.5
automatically enlarge image by setting Chrome window-size, but latest Chrome's bug make it not work. So I change the method to set smaller fontsize and larger scale factor.
This temp solution will limit max height and width of exported dataframe. But you could use selenium
converter to get rid of it.
@moshemoshe137 Thank you for the temporary workaround! I'm on a Mac using dataframe-image==0.1.5
and ended up going with the developer version of Chrome, which can be installed alongside Chrome.
I updated my code using your example (referenced below) and it fixed the issue I was having:
dfi.export(
styled_df,
str(filepath),
chrome_path="/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev",
)
I'm not sure if it's related, but the issue I had was I kept getting the following warning while running a Jupyter Notebook when I tried to use dfi.export() and the image wouldn't save locally.
Class WebSwapCGLLayer is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framework/Versions/A/Frameworks/libANGLE-shared.dylib (0x7ffb4348f378) and /Applications/Google Chrome.app/Contents/Frameworks/Google Chrome Framework.framework/Versions/112.0.5615.49/Libraries/libGLESv2.dylib (0x1115b39c8). One of the two will be used. Which one is undefined.
I'm using the chrome dev 114.0.5720.4 but still getting errors
db_styled.export_png('test.png')
C:\Program Files\Google\Chrome Dev\Application\chrome.exe
C:\Program Files\Google\Chrome Dev\Application\chrome.exe
C:\Program Files\Google\Chrome Dev\Application\chrome.exe
C:\Program Files\Google\Chrome Dev\Application\chrome.exe
C:\Program Files\Google\Chrome Dev\Application\chrome.exe
C:\Program Files\Google\Chrome Dev\Application\chrome.exe
C:\Program Files\Google\Chrome Dev\Application\chrome.exe
C:\Program Files\Google\Chrome Dev\Application\chrome.exe
Unable to enlarge image with chrome
please try 'df.dfi.export('df.png', table_conversion="selenium", max_rows=-1)'
and if I try running the suggested command I get
db_styled.dfi.export('df.png', table_conversion="selenium", max_rows=-1)
*** AttributeError: 'Styler' object has no attribute 'dfi'
What to do?
I'm using the chrome dev 114.0.5720.4 but still getting errors
db_styled.export_png('test.png') C:\Program Files\Google\Chrome Dev\Application\chrome.exe C:\Program Files\Google\Chrome Dev\Application\chrome.exe C:\Program Files\Google\Chrome Dev\Application\chrome.exe C:\Program Files\Google\Chrome Dev\Application\chrome.exe C:\Program Files\Google\Chrome Dev\Application\chrome.exe C:\Program Files\Google\Chrome Dev\Application\chrome.exe C:\Program Files\Google\Chrome Dev\Application\chrome.exe C:\Program Files\Google\Chrome Dev\Application\chrome.exe Unable to enlarge image with chrome please try 'df.dfi.export('df.png', table_conversion="selenium", max_rows=-1)'
and if I try running the suggested command I get
db_styled.dfi.export('df.png', table_conversion="selenium", max_rows=-1) *** AttributeError: 'Styler' object has no attribute 'dfi'
What to do?
import dataframe_image
@PaleNeutron Thanks yes I run that, but for example if you run the following code with fs = 15px
the resulting image is ok, but if you try with fs = 35px
you get the Unable to enlarge image with chrome
warning and the resulting image is cropped.
import pandas as pd
import numpy as np
db = pd.DataFrame(np.random.randint(-9,9,size=(20, 15)), columns='AAA1 AAA2 BBB1 BBB2 CCC1 CCC2 DDD1 DDD2 EEE1 EEE2 EEE3 EEE4 FFF1 FFF2 FFF3'.split())
bool_matrix = (db < 0)*-1 + (db == 0)*0 + (db > 0)*1
def cells_color(value):
return 'color: ' + bool_matrix.applymap(lambda x: '#00b200' if x==1 else 'red' if x==-1 else 'black')
fs = '15px'
cells_font = [dict(selector="th", props=[('font-size', fs), ('text-align', 'center')]),
dict(selector="td", props=[('font-size', fs), ('text-align', 'right')])]
db_styled = (db.style.apply(cells_color, axis=None)
.set_table_styles(cells_font))
import dataframe_image
db_styled.export_png('test.png')
Thanks to @benjaminmoritz
I installed Google Chrome Developer Version from https://www.google.com/intl/de/chrome/dev/
Then set the chrome_path following:
dfi.export(df, 'filename_png, fontsize=3.8, dpi=800, table_conversion='chrome', chrome_path='C:\Program Files\Google\Chrome Dev\Application\chrome.exe',max_rows=-1)
And it works for me!
Hi, I tried using table_converter = 'selenium' and received the following error:
'SeleniumScreenshot' object has no attribute 'css'
The error is coming inside the def run(self, html) block. I had copy pasted the code in the _screenshot file that was posted by @wosantos95 for exporting table images using selenium. @waterbear1996
Any help with this would be appreciated. Thanks.
I cut my table in two and then it was fine