question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

matplotlib.pyplot error when importing: ImportError: No module named '_tkinter', please install the python3-tk package

See original GitHub issue

It looks like there is some package missing (python3-tk?), which prevents from normal usage of matplotlib.pyplot. Is there any workaround for this issue? Thanks!

Python 3.6.3 (default, Oct  6 2017, 08:44:35) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot
Traceback (most recent call last):
  File "/usr/lib/python3.6/tkinter/__init__.py", line 37, in <module>
    import _tkinter
ModuleNotFoundError: No module named '_tkinter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/pyplot.py", line 116, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/backends/__init__.py", line 60, in pylab_setup
    [backend_name], 0)
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
    from six.moves import tkinter as Tk
  File "/usr/local/lib/python3.6/dist-packages/six.py", line 92, in __get__
    result = self._resolve()
  File "/usr/local/lib/python3.6/dist-packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/usr/local/lib/python3.6/dist-packages/six.py", line 82, in _import_module
    __import__(name)
  File "/usr/lib/python3.6/tkinter/__init__.py", line 39, in <module>
    raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
ufoymcommented, May 2, 2018

When you want to use matplotlib in deepo, we suggest using a non-interactive backend such as agg. In your figure-generating script, just call the matplotlib.use() directive before importing pylab or pyplot:

import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
plt.plot([1,2,3])
plt.savefig('myfig')
0reactions
ksajjancommented, Sep 4, 2018

Hi, In the below case

This call to matplotlib.use() has no effect because the backend has already

Just restart the terminal.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - matplotlib error - no module named tkinter
Go to start menu, type Apps & features,; Search for "python" in the search box,; Select the Python version (e.g. Python 3.8.3rc1(32-bit)) and...
Read more >
Getting "No module named '_tkinter'" error · Issue #9017
I installed matplotlib using pip.. I installed Python 3.6 from source though, omitting the tk packages as I didn't need them. Guess I' ......
Read more >
ModuleNotFoundError: No module named 'tkinter' in Python
The Python "ModuleNotFoundError: No module named 'tkinter'" occurs when tkinter is not installed in our Python environment.
Read more >
Python error ImportError No module named tkinter please ...
I am trying to install python on Linux and I am getting the following error: ImportError: No module ... package. How do I...
Read more >
No module named _tkinter, please install the python-tk package
You are getting this error because you have not installed tkinter locally. You can run the install command to download and install tkinter....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found