1

Every time I tried to run import matplotlib, I have error ImportError: No module named Tkinter.

The output result is as listed below:

Python 2.7.5 (default, Aug  2 2016, 04:20:16) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
from six.moves import tkinter as Tk
File "/usr/lib/python2.7/site-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/lib/python2.7/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/lib/python2.7/site-packages/six.py", line 82, in _import_module
__import__(name)
ImportError: No module named Tkinter

I tried to install the tk.x86_64 and tk-devel.x86_64 packages, and tried to reinstall the python package but the error still appeared. Also I tried to import Tkinter but I got the following error.

Python 2.7.5 (default, Aug  2 2016, 04:20:16) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named Tkinter

Does anyone have a workaround for this error?

5 Answers 5

3

I'm using python2.7.12 on ubuntu16.04. I installed it with this command:

sudo apt-get install python-tk
Sign up to request clarification or add additional context in comments.

Comments

2

I tried to install tkinter package for python2.7.5 from the following link: tkinter package Also I found there is dependency library libTix.so()(64bit) for tkinter package and i got it from the following link: libTix.so()(64bit) package after that i installed both then I could import Tkinter and import matplotlib.pyplot as plt with no errors.

1 Comment

Glad you managed to install the packages you needed and fixed your problem.
1

My 2 cents. Open a terminal and type the following.

$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>>

If you do not get an error like below then your Tkinter is fine and the problem is with matplotlib. Then try removing and reinstalling matplotlib.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named tkinter

1 Comment

I forgot to add i tried to import Tkinter and i have got mentioned error as following python 2.7.5 (default, Aug 2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import Tkinter Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named Tkinter
1

I was getting the error "ImportError: No module named '_tkinter'" for python3.5 in-spite of installing python3-tk and tkinter-dev.

It showed the error in following file:

File "/usr/local/lib/python3.5/tkinter/init.py", line 35, in import _tkinter # If this fails your Python may not be configured for Tk

It got resolved for me by simply running the python from /usr/bin like /usr/bin/python3.5 from terminal!

In short, please ensure the python version being run from terminal has the tkinter installed and configured :)

My PC configuration: Ubuntu16.04 with default python2.7 and python3.5

Comments

1

I faced the same issue on a RHEL 7 machine. There was no python-tk package that could be installed. I found the solution here which solved the issue for me:

sudo yum install tkinter

This should work for RHEL machines using Python 2.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.