Ubuntu – How to install tkinter for both python 3.4 and python 3.5

pythonsoftware installationtkinter

How can I install tkinter for both python 3.4 and python 3.5?

Currently, tkinter is installed for python 3.4 (i.e., import tkinter runs fine in the python 3.4 interpreter). However I don't know how to install tkinter for python 3.5.

sudo apt-get install python3-tk doesn't work: it says python3-tk is already installed (which is unsurprising since it is installed for python 3.4).

I use Ubuntu 14.04.4 LTS x64.


python3.4:

jh@gr:/scratch/test$ python3.4
Python 3.4.3 (default, Nov 17 2016, 01:08:31)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>

python3.5:

jh@gr:/scratch/test$ python3.5
Python 3.5.2 (default, Jul 17 2016, 00:00:00)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
Traceback (most recent call last):
  File "/usr/lib/python3.5/tkinter/__init__.py", line 36, in <module>
    import _tkinter
ImportError: 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/lib/python3.5/tkinter/__init__.py", line 38, in <module>
    raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package

As a side note, restinstalling the package python3-tk doesn't change the situation (i.e., afterward tkinter works in python 3.4 and not in python 3.5):

sudo apt-get remove python3-tk
sudo apt-get install python3-tk

Best Answer

Try this:

sudo apt-get install python3.5-tk
Related Question