【问题标题】:Getting this PYTHON value error inside docker container在 docker 容器中获取此 PYTHON 值错误
【发布时间】:2021-03-11 11:44:14
【问题描述】:

我在这个简单的程序中使用这个 python pandas & dataframe_image 包。我正在尝试将数据帧输出(df)导出到 PNG 文件。但是在 docker 容器中出现此错误。但它在机器上工作。

谁能帮我解决这个问题?

>>> import numpy as np
>>> import pandas as pd
>>> df = pd.DataFrame(np.random.rand(6,4))
>>> print(df)
          0         1         2         3
0  0.330808  0.781473  0.932547  0.440994
1  0.777121  0.101482  0.451317  0.020650
2  0.615397  0.973937  0.518510  0.454620
3  0.636042  0.009769  0.983006  0.618849
4  0.021588  0.276602  0.811048  0.928457
5  0.892482  0.355014  0.050483  0.275732
>>> import dataframe_image as dfi
>>> dfi.export(df, 'df_styled.png')
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_CA.UTF-8)
[1129/005716.614490:ERROR:bus.cc(393)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: Connection refused
[1129/005716.834742:INFO:headless_shell.cc(616)] Written to file /tmp/tmprz2n4mrq/temp.png.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/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.9/site-packages/dataframe_image/_pandas_accessor.py", line 73, in _export
    img_str = converter(html)
  File "/usr/local/lib/python3.9/site-packages/dataframe_image/_screenshot.py", line 168, in run
    img_str = self.finalize_image(img)
  File "/usr/local/lib/python3.9/site-packages/dataframe_image/_screenshot.py", line 159, in finalize_image
    mimage.imsave(buffer, img)
  File "/usr/local/lib/python3.9/site-packages/matplotlib/image.py", line 1577, in imsave
    rgba = sm.to_rgba(arr, bytes=True)
  File "/usr/local/lib/python3.9/site-packages/matplotlib/cm.py", line 313, in to_rgba
    if norm and (xx.max() > 1 or xx.min() < 0):
  File "/usr/local/lib/python3.9/site-packages/numpy/core/_methods.py", line 39, in _amax
    return umr_maximum(a, axis, None, out, keepdims, initial, where)
ValueError: zero-size array to reduction operation maximum which has no identity

DBus 正在虚拟机上运行。现在出现以下错误。

 /etc/init.d/dbus status
● dbus.service - D-Bus System Message Bus
   Loaded: loaded (/lib/systemd/system/dbus.service; static; vendor preset: enabled)
   Active: active (running) since Mon 2020-11-30 01:43:57 UTC; 57s ago
     Docs: man:dbus-daemon(1)
 Main PID: 957 (dbus-daemon)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/dbus.service
           └─957 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only


>>> import numpy as np
>>> import dataframe_image as dfi
>>> import pandas as pd
>>> df = pd.DataFrame(np.random.rand(6,4))
>>> dfi.export(df, '/home/nr/testing/df_styled.png')
[1130/014613.802954:INFO:headless_shell.cc(616)] Written to file /tmp/tmp33yqzne1/temp.png.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-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/dist-packages/dataframe_image/_pandas_accessor.py", line 73, in _export
    img_str = converter(html)
  File "/usr/local/lib/python3.6/dist-packages/dataframe_image/_screenshot.py", line 168, in run
    img_str = self.finalize_image(img)
  File "/usr/local/lib/python3.6/dist-packages/dataframe_image/_screenshot.py", line 159, in finalize_image
    mimage.imsave(buffer, img)
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/image.py", line 1577, in imsave
    rgba = sm.to_rgba(arr, bytes=True)
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/cm.py", line 313, in to_rgba
    if norm and (xx.max() > 1 or xx.min() < 0):
  File "/usr/local/lib/python3.6/dist-packages/numpy/core/_methods.py", line 39, in _amax
    return umr_maximum(a, axis, None, out, keepdims, initial, where)
ValueError: zero-size array to reduction operation maximum which has no identity
>>>

【问题讨论】:

    标签: python image dataframe


    【解决方案1】:

    看起来dataframe_image 需要dbus 启动并运行以处理无头程序(浏览器?)并拍摄快照。这通常不会在 Docker 容器中完成。您需要以某种方式提出它,这通常由 systemd 在当前发行版中完成。

    如果这是一个开发容器,您可以在每次启动容器时手动使用systemd 将其打开。如果这需要完全解决,您需要重新考虑您的entrypoint,无论是在容器内安装和使用systemd,还是查看它如何启动dbus 并将其复制到那里。

    看这里:https://askubuntu.com/questions/813588/systemctl-failed-to-connect-to-bus-docker-ubuntu16-04-container

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-06
    • 1970-01-01
    • 1970-01-01
    • 2019-06-29
    • 1970-01-01
    • 2017-12-25
    • 2021-08-04
    • 1970-01-01
    相关资源
    最近更新 更多