2

I am trying to import matplotlib.pyplot using python3.6, but an error appear.

ModuleNotFoundError: No module named '_tkinter

Importing tkinter directly in a python script gives the same error.

I have also tried installing tkinter, but still fail to be imported in python3.6

$ sudo apt-get install python3-tk
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-tk is already the newest version (3.5.1-1).
The following packages were automatically installed and are no longer required:
  libexpat1:i386 libmpdec2:i386 libpython3-dev libpython3-stdlib:i386 libpython3.5-dev libpython3.5-minimal:i386
  libpython3.5-stdlib:i386 libreadline6:i386 libsnapd-glib1 libsqlite3-0:i386 libssl1.0.0:i386 linux-headers-4.13.0-36
  linux-headers-4.13.0-36-generic linux-headers-4.13.0-37 linux-headers-4.13.0-37-generic linux-headers-4.13.0-38
  linux-headers-4.13.0-38-generic linux-image-4.13.0-36-generic linux-image-4.13.0-37-generic linux-image-4.13.0-38-generic
  linux-image-extra-4.13.0-36-generic linux-image-extra-4.13.0-37-generic linux-image-extra-4.13.0-38-generic
  linux-signed-image-4.13.0-37-generic linux-signed-image-4.13.0-38-generic snapd-login-service
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

$ python
Python 3.6.3 (default, Apr 13 2018, 13:00:29) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/tkinter/__init__.py", line 36, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'

Installing python3.6-tk gives

 $ sudo apt-get install python3.6-tk
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package python3.6-tk
E: Couldn't find any package by glob 'python3.6-tk'
E: Couldn't find any package by regex 'python3.6-tk'

Matplotlib and tkinter work fine when using python2.7 and 3.5. I guess the problem is to install tkinker for python3.6, but I failed to install it.

Thanks

  • Maybe the [accepted answer here](https://stackoverflow.com/questions/50327906/importerror-no-module-named-tkinter-please-install-the-python3-tk-package) will help you? – Billal Begueradj May 17 '18 at 04:48
  • @BillalBEGUERADJ The answer allows me to import matplotlib without error, but still cannot generate the plots visually using plt.show(). So I might still want to install tkinter. – Watsup MyMan May 17 '18 at 05:33

0 Answers0