0

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.

1
  • 2
    did you by any change change any of your environment variables or installed any application that has a built-in python interpreter that also messed with your environment variables ? like PATH ? you might want to check it. Commented Oct 13, 2022 at 19:54

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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:\Users\Admin\AppData\Local\Programs\Python\Python36\python.exe -m pip install numpy
    

    enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.