Ubuntu – ImportError: No module named tkinter

14.04pythonpython-2.7tkinter

When I try to install tkinter using this command:

sudo apt-get install python-tk

I get this message meaning it is already installed:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-tk is already the newest version.
The following package was automatically installed and is no longer required:
  libjpeg62
Use 'apt-get autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.

When I want to import it, I get this message error:

begueradj@begueradj-darwin:~/begueradj# python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from tkinter import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named tkinter
>>> 

How to fix this ?

Best Answer

To use Tkinter, all you need to do is to import one module:

import Tkinter

Or, more often:

from Tkinter import *

So just change your import line to import Tkinter for example:

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>> Tkinter.TkVersion
8.6
>>> 

Source: https://docs.python.org/2/library/tkinter.html#tkinter-modules