Why difference between terminal and IDE?

Hi,
I’m trying to use tkinter and I have several problems I think because an error occurs :

ModuleNotFoundError: No module named 'tkinter'

I call

from tkinter import *

I use Fedora 40 and VScode.

1rst problem
In the terminal of VScode it’s python 3.11.9 and the sys.path is /usr/lib/…
In the terminal of fedora it’s python 3.12.4 and the sys.path is /usr/lib64/…

2nd problem
Even if I have the nomodule error, I try in both terminals (vscode and fedora) to install tkinter :

pip install tk
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: tk in /var/data/python/lib/python3.11/site-packages (0.1.0)

Do you know why I can’t use this ?

The python in your path and the python used by your IDE are different. You should always use virtual environments instead. Install packages in a virtual environment using pip and venv - Python Packaging User Guide

In vs code you can select your python interpreter at the bottom right corner of any python editor, (with the python extension enabled, of course :grinning: )

If it’s still relevant, trying to look which python version it’s actually activated with ‘which python3’ command. Also trying to list packagesin your python version looking for tkinter. Last thing, i don’t know about fedora but for linux environments tkinter should come when you install python3 … something like python3-tkinter.