Home > Software design >  ImputError: No module named 'tkinter'
ImputError: No module named 'tkinter'

Time:11-18

I am new to python and wanted to code a simple application to practice a bit more but for whatever reason it is saying there is no module named 'tkinter'. I've tested to make sure tkinter is installed using python -m Tkinter and it works but tkinter won't work with my project. I am using pop_os! Linux and I am using Visual Studio Code as my IDE

Traceback (most recent call last):
  File "first_game.py", line 2, in <module>
    from tkinter import *
ImportError: No module named tkinter

CodePudding user response:

Capitalisation matters when it comes to names in Python. In Python 2, the library is called Tkinter. In Python 3, it has been renamed tkinter to be consistent with the rest of the standard library.

You can check which version of Python your command line is running with python --version, or by running the following script:

import sys
print(sys.version)

CodePudding user response:

If python -m Tkinter works, then you need to do from Tkinter import *. Case matters when importing packages.

However, if python -m Tkinter works that means you're using python 2.x which is no longer supported. It would be best to switch to python 3.x, in which case the package is named tkinter rather than Tkinter.

  • Related