0

I am building an application in Python. A while ago, I was able to debug it without any issues, but after accidently reseting my VS Code settings, I am not able anymore. Whenever I try to debug I get the following error on the first installed library I try to import:

Exception has occurred: ModuleNotFoundError No module named
'PySimpleGUI'

When I try to install the library using pip3, I get the message:

Requirement already satisfied: PySimpleGui in c:\users\adassa\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages

When I run directly from the console using python3 name_of_file.py, the file runs without any problems. Here is my launch.json for debugging:

{
    "version": "0.2.0",
    "configurations": [
        {
           "name": "Python: Current File",
           "type": "python",
           "request": "launch",
           "program": "${file}",
           "console": "integratedTerminal",
           "env": { "PYTHONPATH": "${workspaceRoot}"}
        }
    ]
}

I read in other questions that this error has to do with different installations of Python, and the debugger trying to find the library on the wrong directory, but couldn't understand how to solve it.

I tried replacing PYTHONPATH with the path of python3 I get from the console. (I obtaineed that path using the command from this answer: https://stackoverflow.com/a/647798/14874778, but the error remains. How can I solve this problem?

1 Answers1

0

Do you have multiple python installations? If so, try something that looks like this (made for python 3.7.9 & Windows):

py -3.7 -m pip install pysimplegui

This has always worked for me. You can also try specifying which installation you want to run the script, which should look like this (also 3.7.9, also Windows):

py -3.7 helloworld.py
msp729
  • 1
  • 2
  • Yes, I do have multiple installations, I'd like to delete the others, but am not sure how. But anyway, your solution is to install the library on the version that is being used by the debugger, but what I'd like to do is to run the same version that runs when I just type python3 on the debugger. Otherwise I'd have to install every library twice. – Thiago Pereira Maia Apr 02 '21 at 14:20
  • You're on Windows 10, right? Go to Settings (Win+I), Apps, and then search through the list for "python". You should see the Python Launcher as well as every installation of Python that's on your computer. If you click on one, you can uninstall it. – msp729 Apr 02 '21 at 14:31