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.
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.Checking 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:
- install
tcl-tk
with Homebrew. In shell runbrew install tcl-tk
- in shell run
echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrc
- reload shell by quitting
Terminal
app or runsource ~/.zshrc
- after reloaded check that
tck-tk
is in$PATH
. Runecho $PATH | grep --color=auto tcl-tk
. As the result you should see your $PATH contents withtcl-tk
highlighted - now we run three commands from Homebrew's output from step #1
- in shell run
export LDFLAGS="-L/usr/local/opt/tcl-tk/lib"
- in shell run
export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"
- in shell run
export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig"
- in shell run
- if you have your Python version already installed with
pyenv
then uninstall it withpyenv uninstall <your python version>
. E.g.pyenv uninstall 3.8.2
- set environment variable that will be used by
python-build
. In shell runPYTHON_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 usetck-tk
version that actually installed with Homebrew. At the moment of posting8.6
was the actual - finally install Python with
pyenv
withpyenv install <version>
. E.g.pyenv install 3.8.2
Test
- in shell run
pyenv global <verion that you've just installed>
- now check IDLE. In shell run
idle
. You should see IDLE window without any warnings and "text printed in red".
- now check
tkinter
. In shell runpython -m tkinter -c "tkinter._test()"
. You should see test window like on the image:
That's it!
My environment:
check this is something went wrong executing steps above:
- macOS Catalina
zsh
(included in macOS Catalina) = "shell" above- Homebrew (installed with instructions from Homebrew official website)
pyenv
(installed with Homebrew and PATH updated according topyenv
official readme from GitHub)- Python
3.8.x
-3.9.x
(installed withpyenv 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
Why Does Random.Shuffle Return None
How to Install Python3 Version of Package via Pip on Ubuntu
Directory-Tree Listing in Python
How to Initialize a Two-Dimensional Array in Python
Scrape Multiple Urls Using Qwebpage
Efficient String Matching in Apache Spark
Understanding Nested List Comprehension
Removing Emojis from a String in Python
What Rules Does Pandas Use to Generate a View VS a Copy
How to Get the Number of Elements in a List in Python
Multiprocessing Global Variable Updates Not Returned to Parent
Difference Between _Getattr_ and _Getattribute_
How to Manage Local VS Production Settings in Django
How to Create a Guid/Uuid in Python
Why Does the Print Function Return None
How to .Decode('String-Escape') in Python 3
Python Nameerror: Name Is Not Defined
Python 2.7 Getting User Input and Manipulating as String Without Quotations