Python Forum
[SOLVED] Tkinter module not found - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: [SOLVED] Tkinter module not found (/thread-37886.html)



[SOLVED] Tkinter module not found - Milan - Aug-02-2022

Hello team,

So I installed tkinter using

pip3 install tk
But when I try to run the following code

import tkinter as tk

root = tk.Tk()
root.mainloop()
I get the following error:
Traceback (most recent call last):
  File "iwannadie.py", line 1, in <module>
    import tkinter as tk
ModuleNotFoundError: No module named 'tkinter'
This is driving me crazy, because I have the tk lib installed

pip3 list | grep tk             
tk                             0.1.0    


And tried to import it in different ways

import tkinter as tk
from tkinter import *
import tk


Nothing seems to work, could you please help?

[SOLVED]

Run command
sudo apt-get install python3-tk


RE: Tkinter module not found - ndc85430 - Aug-02-2022

Tkinter comes with Python. tk that you've installed is something else: https://pypi.org/project/tk/.

It's odd that you can't import tkinter, though. More information, please. Which Python version? Are you using a virtual environment, or have you got any custom set up in terms of where Python is looking for libraries?


RE: Tkinter module not found - Milan - Aug-02-2022

Currently using python 3.8, not a virtual environment.


RE: Tkinter module not found - rob101 - Aug-02-2022

(Aug-02-2022, 07:17 PM)ndc85430 Wrote: Tkinter comes with Python.

Not always: I had to sudo apt-get install python3-tk on my Linux system.

Quote:Ubuntu Linux 20.04:

To conserve memory space, the default version of the Python interpreter that comes pre-installed on Ubuntu Linux 20.04 has no support for Tkinter. However, if you want to continue using the Python interpreter bundled with your operating system, then install the following package:

link: https://realpython.com/python-gui-tkinter/


RE: Tkinter module not found - menator01 - Aug-02-2022

I usually do python3 -m pip install module. Ensures that I'm installing to the correct python version.


RE: Tkinter module not found - Milan - Aug-02-2022

(Aug-02-2022, 07:21 PM)Milan Wrote: Currently using python 3.8, not a virtual environment.

Running sudo apt-get install python3-tk solved it, I am also on linux. Thank you very much.


RE: [SOLVED] Tkinter module not found - Larz60+ - Aug-02-2022

Try this: https://docs.python.org/3/library/tkinter.html#a-hello-world-program


RE: [SOLVED] Tkinter module not found - woooee - Aug-05-2022

FYI, if your software manager does not resolve dependencies like Ubuntu does. you may also have to install TCL and TK. Tkinter is just a Python wrapper around the tool kit.