skip to Main Content

My python GUI has been working fine from VSCode for months now, but today (with no changes in the code that I can find) it has been throwing me an error in the form of:

Exception has occurred: ModuleNotFoundError
No module named ‘_tkinter’

This error occurs for any import that is not commented out. The GUI works as intended when ran from the terminal using "python3 filename.py",but the run/debug function in VSCode keeps throwing that same error. I’m relatively new here so I have no clue what the problem could be, any insight or things to try would be appreciated.

2

Answers


  1. Press Ctrl+Shift+P and type "select interpreter", press Enter and select the python interpreter path that you want to use by default in current project.

    If currently selected one does not have some libraries installed, you may see error from Pylance.

    Login or Signup to reply.
  2. The cause of this problem may be that there are multiple python versions on your machine, and the interpreter environment you are currently using is not the same environment where you installed the third-party library.

    Solution:

    1. Use the following code to get the current interpreter path

      import sys
      print(sys.executable)
      

      enter image description here

    2. Copy the resulting path, and then use the following commands to install third-party libraries for the current environment (using numpy as an example)

      C:UsersAdminAppDataLocalProgramsPythonPython36python.exe -m pip install numpy
      

      enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search