kay00
kay00

Reputation: 447

Import error with Tkinter and python3.5

I am having trouble running matplotlib.pyplot and tkinter with python3.5. I am on Ubuntu 12.04.5 LTS. I see that python3-tk installed when I type dpkg -l python3-tk. How else should I troubleshoot?

Is python3-tk only for python3.2 not python3.5?

Examples below with python3.2 versus python3.5

machine:~$ /usr/bin/python3
Python 3.2.3 (default, Jun 18 2015, 21:46:58)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> exit()

machine:~$ /usr/bin/python3.5
Python 3.5.2 (default, Jul 17 2016, 17:38:18)
[GCC 4.6.3] 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

python3-tk is installed

machine:~$ dpkg -l python3-tk
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                         Version                      Description
    +++-============================-============================-

========================================================================
ii  python3-tk                   3.2.3-1                      Tkinter - Writing Tk applications with Python 3.x

Upvotes: 3

Views: 4783

Answers (4)

yogesh agrawal
yogesh agrawal

Reputation: 726

I tried using this command in ubuntu16.02 it works

sudo apt-get install python3.5-tk

as by default i had python2.7 installed.you can refer this link

Upvotes: 0

Paul Azunre
Paul Azunre

Reputation: 21

Change the matplotlib backend to 'agg' or some other noninteractive option. Something like the following:

matplotlib.use('agg')

More info here (in the context of Docker, where I faced this issue and successfully solved it):

Upvotes: 2

Denny
Denny

Reputation: 163

sudo apt-get install python3-tk

This command will install tkinter for your default python3 only, so python3.5 ImportError.

You can run the following command to install for python3.5

sudo apt-get install python3.5-tk

Upvotes: 3

kay00
kay00

Reputation: 447

The python3-tk libraries were installed under the 3.2 version, not 3.5. Python3-tk was uninstalled and python3.5-tk was installed instead

Upvotes: 0

Related Questions