Python Forum
[SOLVED] Tkinter module not found
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] Tkinter module not found
#1
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
Reply
#2
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?
Reply
#3
Currently using python 3.8, not a virtual environment.
Reply
#4
(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/
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#5
I usually do python3 -m pip install module. Ensures that I'm installing to the correct python version.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#6
(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.
Reply
#7
Try this: https://docs.python.org/3/library/tkinte...ld-program
Reply
#8
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.
Gribouillis likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pyside6 module not found ForeverNoob 4 1,275 Aug-18-2023, 04:36 PM
Last Post: snippsat
  [SOLVED] [BeautifulSoup] Why attribute not found? Winfried 0 728 Mar-11-2023, 10:00 PM
Last Post: Winfried
  Module Not Found Error bitoded 4 1,346 Jan-01-2023, 09:08 AM
Last Post: bitoded
  pdfminer package: module isn't found Pavel_47 25 8,416 Sep-18-2022, 08:40 PM
Last Post: Larz60+
  Module not found question sighhhh12 0 1,448 Sep-09-2022, 05:43 AM
Last Post: sighhhh12
  No module found when I run a main.py tomtom 2 1,414 Jul-20-2022, 09:24 AM
Last Post: tomtom
  No Module found in other directory than source code [SOLVED] AlphaInc 1 2,004 Nov-10-2021, 04:34 PM
Last Post: AlphaInc
  KafkaUtils module not found on spark 3 pyspark aupres 2 7,261 Feb-17-2021, 09:40 AM
Last Post: Larz60+
  'urllib3' Module not found when import 'requests' spanz 5 9,963 Jan-06-2021, 05:57 PM
Last Post: snippsat
  no module named finbert found ErnestTBass 4 4,488 Dec-05-2020, 06:09 PM
Last Post: andrianas

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020