Matplotlib missing _tkinter

I have problem with running test for matplotlib==2.0.2 even I installed some recommended packages

- sudo apt-get install tk-dev
- sudo apt-get install pkg-config
- sudo apt-get install python-dev
- sudo apt-get install python-tk

I get folowing error:

import matplotlib.pyplot as plt

…/virtualenvs/venv-2.7.9/lib/python2.7/site-packages/matplotlib/pyplot.py:115: in
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
…/virtualenvs/venv-2.7.9/lib/python2.7/site-packages/matplotlib/backends/init.py:32: in pylab_setup
globals(),locals(),[backend_name],0)
…/virtualenvs/venv-2.7.9/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py:6: in
from six.moves import tkinter as Tk
…/virtualenvs/venv-2.7.9/lib/python2.7/site-packages/six.py:203: in load_module
mod = mod._resolve()
…/virtualenvs/venv-2.7.9/lib/python2.7/site-packages/six.py:115: in _resolve
return _import_module(self.mod)
…/virtualenvs/venv-2.7.9/lib/python2.7/site-packages/six.py:82: in _import_module
import(name)
/opt/circleci/.pyenv/versions/2.7.9/lib/python2.7/lib-tk/Tkinter.py:39: in
import _tkinter # If this fails your Python may not be configured for Tk
E ImportError: No module named _tkinter

finally what helped me is having in code calling matplotlib following:

if os.environ.get('DISPLAY', '') == '':
    logging.warning('No display found. Using non-interactive Agg backend.')
    matplotlib.use('Agg')

and later in in the config suppressing DISPLAY

- unset DISPLAY && python ...

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.