5
votes

Ok, I am having a weird issue going on. From what I understand Tkinter is supposed to be built in with python 2 and 3.

I can import and use Tkinter just fine in my terminal under python3 as well as with IDLE3. However, when I try to import Tkinter in Visual Studio Code I get an "ImportError: No module named 'tkinter'.

The same issue was happening in Pycharm also but I had my interpreter set to the same as my terminal and not a project-specific interpreter.

I have tried the following:

import tkinter
from tkinter import *
try:
    import tkinter
except ImportError:
    import Tkinter as tkinter #Even though I'm using python3

None of this is working, Any idea why? Also I am using Linux Mint.

2
are you using venv? - Moshe Slavin
@MosheSlavin no. At least I haven't told it to create a virtual environment. - Robotica
are you aware it's Tkinter in python 2, and tkinter in python 3? - Bryan Oakley
@BryanOakley yeah I am using python 3, and I have been importing it as tkinter, the only reason I did the try/except with the python2 syntax was to see if my IDE was for some reason going by python2. - Robotica

2 Answers

1
votes

In windows you could have selected to not install the needed tkinter components when python was installed (its optional in the installer).

Try running the installer again, and make sure these components are selected.

1
votes

I've been stuck with the same issue for weeks now where my VSC says there are no tkinter module but in shell and terminal it runs fine.

Solution: I found out that in the left buttom corner there is an interpreter that runs as Python 2 just click and select Python 3