Importerror: No Module Named 'Tkinter'

ImportError: No module named 'Tkinter'

You probably need to install it using something similar to the following:

  • For Ubuntu or other distros with Apt:

    sudo apt-get install python3-tk
  • For Fedora:

    sudo dnf install python3-tkinter

You can also mention a Python version number like this:


  • sudo apt-get install python3.7-tk

  • sudo dnf install python3-tkinter-3.6.6-1.fc28.x86_64

Finally, import tkinter (for Python 3) or Tkinter (for Python 2), or choose at runtime based on the version number of the Python interpreter (for compatibility with both):

import sys
if sys.version_info[0] == 3:
import tkinter as tk
else:
import Tkinter as tk

no module named 'Tkinter' on windows

You need to check the option tcl/tk and IDLE when installing Python on Windows. Retroactive installation through pip doesn't work.

ModuleNotFoundError: No module named '_tkinter' on macOS

For Python3 tkinter can be simply installed by,

brew install python-tk

pip sometimes wont work successfully on my Mac, especially with the High Sierra OS version. Brew can be used to install all kinds of software packages in mac.

matplotlib error - no module named tkinter

For Linux

Debian based distros:

sudo apt-get install python3-tk

RPM based distros:

sudo yum install python3-tkinter

For windows:

For Windows, I think the problem is you didn't install complete Python package. Since Tkinter should be shipped with Python out of box. See: http://www.tkdocs.com/tutorial/install.html . Good python distributions for Windows can be found by the companies Anaconda or ActiveState.

Test the python module

python -c "import tkinter"

p.s. I suggest installing ipython, which provides powerful shell and necessary packages as well.

No module named 'tkinter' (Python3.8) in Windows

Just re-install python..

tkinter (and the associated system libraries it needs) are meant to be included by default with any version of python you install. If it got deleted or corrupted (or not installed in the first place), it is easiest often just to re-install python. If you want to keep all the libraries you've already installed, copy c:\Python38\Lib\site-packages somewhere safe, then you can go ahead and delete the python folder. Next you'll want to search using the start menu for "environment variables", and select "edit environment variables for your account". Select the "Path" variable, and click the "edit" button. Delete any entries referring back to the python folder you just deleted.remove old references to the old python installation from the system search path

The recommended windows installer from python.org for 3.8.7 includes several options if you "customize installation" including whether or not to install tkinter as well as where you want to install.python 3.8.7 64 bit windows installerChecking the entry for "add to PATH" will ensure that when you type "python" into a cmd prompt; it works. You can then move your old "site-packages" folder back to your python folder in the same location "pyfolder\Lib\site-packages". If you install a different version of python you should re-install any libraries rather than copying them, but saving site-packages will at least give you a list of what you need to go install.

Python/Tkinter : ModuleNotFoundError: No module named '_tkinter'

Here is step by step guide to make IDLE and tkinter work. Working for me on macOS Catalina. Should be easily adapted to Linux environment:

  1. install tcl-tk with Homebrew. In shell run brew install tcl-tk
  2. in shell run echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrc
  3. reload shell by quitting Terminal app or run source ~/.zshrc
  4. after reloaded check that tck-tk is in $PATH. Run echo $PATH | grep --color=auto tcl-tk. As the result you should see your $PATH contents with tcl-tk highlighted
  5. now we run three commands from Homebrew's output from step #1

    1. in shell run export LDFLAGS="-L/usr/local/opt/tcl-tk/lib"
    2. in shell run export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"
    3. in shell run export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig"
  6. if you have your Python version already installed with pyenv then uninstall it with pyenv uninstall <your python version>. E.g. pyenv uninstall 3.8.2
  7. set environment variable that will be used by python-build. In shell run PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I/usr/local/opt/tcl-tk/include' --with-tcltk-libs='-L/usr/local/opt/tcl-tk/lib -ltcl8.6 -ltk8.6'"
    Note: in future use tck-tk version that actually installed with Homebrew. At the moment of posting 8.6 was the actual
  8. finally install Python with pyenv with pyenv install <version>. E.g. pyenv install 3.8.2

Test

  1. in shell run pyenv global <verion that you've just installed>
  2. now check IDLE. In shell run idle. You should see IDLE window without any warnings and "text printed in red".

IDLE window run from Terminal. No warnings


  1. now check tkinter. In shell run python -m tkinter -c "tkinter._test()". You should see test window like on the image:

tkinter test window

That's it!

My environment:

check this is something went wrong executing steps above:

  1. macOS Catalina
  2. zsh (included in macOS Catalina) = "shell" above
  3. Homebrew (installed with instructions from Homebrew official website)
  4. pyenv (installed with Homebrew and PATH updated according to pyenv official readme from GitHub)
  5. Python 3.8.x - 3.9.x (installed with pyenv install <version> command)

from Tkinter import * ImportError: No module named 'Tkinter'

Lets clear up some basics as it appears you think several things should work that never will.

No mater how you import you will always need to do Tk() with an upper case T by itself or with the appropriate prefix.

Things you have tried that will never work.

root = tk(), Tk.tk(), root = TK.TK()

all lower case tk() or all uppercase TK() will never work in tkinter.

If from tkinter import * doesn't work and doing top = tkinter.Tk() doesn't work it is very likely that you do not have tkinter installed. Or at least it has been removed for some reason.

Windows distro should come with tkinter already. I would try to do a clean install and see what happens. You should update to 3.6 anyway as 3.5 has some bugs that needed to be fixed.

As for your import issue.

from tkinter import * This line should work fine with top = Tk(). So that tells me tkinter is not installed.

import tkinter This redundant line should work as top = tkinter.Tk() but if the previous is not working then this likely wont either.

After doing some testing on PyCharm I can say that if PyCharm failed to load tkinter then it would have errored out first on the import and not the Tk() portion.

Traceback (most recent call last):
File "C:/Users/mcdomi3/PycharmProjects/MintyFlakes/test.py", line 1, in <module>
from Tkinter import *
ModuleNotFoundError: No module named 'tkinter'

Process finished with exit code 1

With that little revaluation I think your install is corrupt.

Conclusion.

You need to reinstall python or try to pip install tkinter as it is missing from your libraries or corrupt somehow.

ModuleNotFoundError: No module named 'Tkinter' error although it has always worked

Be careful, you must use tkinter for Python 3 and Tkinter for Python 2.

So, if you're using Python 3, the module has been renamed to tkinter.

python ImportError: No module named Tkinter

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.



Related Topics



Leave a reply



Submit