dataframe_image icon indicating copy to clipboard operation
dataframe_image copied to clipboard

Save table in Docker problem

Open AlexKay28 opened this issue 4 years ago • 8 comments

Hey there!) I got some problems using the package in docker. I got this traceback inside:

>>> df = pd.DataFrame({"1": [1, 2, 3], "2":[5, 1, 5]})
>>> dfi.export(df, "pic.png")
[0819/121227.333151:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/dataframe_image/_pandas_accessor.py", line 24, in export
    return _export(obj, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path)
  File "/usr/local/lib/python3.6/site-packages/dataframe_image/_pandas_accessor.py", line 73, in _export
    img_str = converter(html)
  File "/usr/local/lib/python3.6/site-packages/dataframe_image/_screenshot.py", line 167, in run
    img = self.take_screenshot()
  File "/usr/local/lib/python3.6/site-packages/dataframe_image/_screenshot.py", line 119, in take_screenshot
    img = mimage.imread(buffer)
  File "/usr/local/lib/python3.6/site-packages/matplotlib/image.py", line 1496, in imread
    with img_open(fname) as image:
  File "/usr/local/lib/python3.6/site-packages/PIL/ImageFile.py", line 121, in __init__
    self._open()
  File "/usr/local/lib/python3.6/site-packages/PIL/PngImagePlugin.py", line 676, in _open
    raise SyntaxError("not a PNG file")
SyntaxError: not a PNG file

Dockerfile with relevant to the issue part:

FROM python:3.6.14-buster

RUN apt-get update && \
    apt install chromium-driver libpng-dev tree -y

COPY requirements.txt .
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

I do use: dataframe-image==0.1.1; matplotlib==3.3.4 I have installed chromedriver ChromeDriver 90.0.4430.212

you can also see libpng-dev installation, it was one of my tries to fix the problem.. so I guess that image may not contains needed utils for the correct working of chromedriver

maybe this problem has already been solved or, can you list what dependencies are needed tho? Thank you!)

AlexKay28 avatar Aug 19 '21 12:08 AlexKay28

I was able to get this working by running the docker container with --privileged. Not ideal, but a temporary workaround until I determine what permissions are required for dataframe_image to write the png file

rogfut avatar Sep 28 '21 05:09 rogfut

I was able to resolve this in a more secure manner by following this post. I am now able to save a table to png in a docker image without having to run as --privileged

rogfut avatar Sep 28 '21 06:09 rogfut

@rogfut thanks you for you answer, but I still have a problem I have tried both variants:

  1. I have tried to add privileged: true string in my docker-compose
  2. I also have tried to add this file and asked docker-compose
security_opt:
  - "seccomp=./chrome.json"

both times I got an error: [0928/124915.366587:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

Could you please describe what you have done in more detail?

AlexKay28 avatar Sep 28 '21 12:09 AlexKay28

@rogfut As I understand, setting "--no-sandbox" parameter while running under a root should solve the problem but is not clear to me how I should set this value if I run chromium latently (

I decided to use custom user It helps me avoid --no-sandbox problem, but SyntaxError: not a PNG file error still exists without privileged: true. (I do not have any permissions problem while running by the way)

as a decision for me yet:

  1. use privileged: true
  2. use created user instead of root

=(

AlexKay28 avatar Sep 28 '21 14:09 AlexKay28

any update on this? still facing the same issue in python-docker.

dharmendrakariya avatar Jul 18 '22 20:07 dharmendrakariya

@ShiraUnger , have you tried the latest 0.1.2 version?

PaleNeutron avatar Sep 05 '22 10:09 PaleNeutron

With setting dataframe_image to version 0.1.2 i still have the issue

FROM ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive

RUN apt update; apt install -y python3-pip
RUN pip install jupyter tqdm pandas==1.4 numpy seaborn==0.11 matplotlib scipy dataframe_image==0.1.2
RUN apt-get update && apt install chromium-driver libpng-dev tree -y

gabrieldernbach avatar Oct 19 '22 15:10 gabrieldernbach

With setting dataframe_image to version 0.1.2 i still have the issue

FROM ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive

RUN apt update; apt install -y python3-pip
RUN pip install jupyter tqdm pandas==1.4 numpy seaborn==0.11 matplotlib scipy dataframe_image==0.1.2
RUN apt-get update && apt install chromium-driver libpng-dev tree -y

I have tried the same image and found error is different:

Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> df = pd.DataFrame({"1": [1, 2, 3], "2":[5, 1, 5]})
>>> import dataframe_image as dfi
>>> dfi.export(df, "pic.png")

Command '/usr/bin/chromium-browser' requires the chromium snap to be installed.
Please install it with:

snap install chromium

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/dataframe_image/_pandas_accessor.py", line 48, in export
    return _export(
  File "/usr/local/lib/python3.8/dist-packages/dataframe_image/_pandas_accessor.py", line 117, in _export
    img_str = converter(html)

Follow this question https://askubuntu.com/questions/1204571/how-to-install-chromium-without-snap

Or use Debian based images

PaleNeutron avatar Oct 21 '22 05:10 PaleNeutron

Move temp html directory under $HOME in 0.2.0 and should solve this problem.

PaleNeutron avatar Sep 05 '23 07:09 PaleNeutron