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.
CodePudding user response:
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.
CodePudding user response:
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:
Use the following code to get the current interpreter path
import sys print(sys.executable)
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