2

I have a python code that has following imports:

from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt

It internally calls tkinter. I am using Amazon EC2 server having CentOS on it. I cannot install tkinter, as OS is headless (no GUI). This link seems to be solution, but it is for Debian OS and does not work for CentOS.

I tried installing desktop referring this link, but that too doesn't work. It gives warning as "WARNING: group GNOME Desktop does not exists." when I ran command yum -y groups install "GNOME Desktop"

Vivek Dani
  • 347
  • 1
  • 4
  • 19

1 Answers1

7

Assuming that you don't want a GUI at all, but let matplotlib produce images on your server, the following might help:

Using a backend without interactive elements should not require tkinter to be present at all.

From the documentation:

There are two types of backends: user interface backends [...] and hardcopy backends to make image files (PNG, SVG, PDF, PS; also referred to as “non-interactive backends”).

Two ways to set the backend (also taken from the link above):

  1. The backend parameter in your matplotlibrc file (see Customizing matplotlib):

    backend : Agg  
    
  2. Inside the script

    import matplotlib
    matplotlib.use('Agg')  
    

    If you use the use() function, this must be done before importing matplotlib.pyplot.

Possible non-interactive backends:

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712