Getting matplotlib gui to work from inside docker based on ROS

asked 2020-07-23 02:44:30 -0500

awa5114 gravatar image

So apparently matplotlib's gui backends don't work out of the box in linux based docker containers. In a previous question I was able to do the following:

I have a simple Docker file in which I am pulling a miniconda image and installing matplotlib on it:

# Comment
FROM conda/miniconda3

RUN pip install matplotlib

I build the image using a docker build command:

docker build -f DockerFile . -t test:test

I then generate a container and access the shell within it:

docker run -it test:test bash

I install some necessary dependencies:

apt-get update

apt-get install libx11-dev

I then start the python interpreter and am able to set the TkAgg backend:

root@0d7701938257:/# python
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.use('TkAgg')

However doing an import matplotlib.pyplot as plt throws an error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2319, in <module>
    switch_backend(rcParams["backend"])
  File "/usr/local/lib/python3.7/site-packages/matplotlib/pyplot.py", line 270, in switch_backend
    newbackend, required_framework, current_framework))
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running

So then I tried to adapt the simplest solution available on a link indicated by @flake as follows:

docker run -it test:test --env="DISPLAY" --env="QT_X11_NO_MITSHM=1" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" osrf/ros:indigo-desktop-full rqt bash

But this throws an error, which I don't understand:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"--env=DISPLAY\": executable file not found in $PATH": unknown.

Which executable does it fail to find and how can I add a path to this? Thanks in advance for your help...

edit retag flag offensive close merge delete