FileNotFoundError on hallucinated site-packages path when starting debug session in VSCode #21250
-
When I run my project in the VSCode debugger, I get a This path is incorrect. It is not where my current Python installation's This is a fresh installation of Python 3.9 (using the official installer from python.org), from which I created a fresh venv, which I then selected as the Python interpreter in my project. There's something very broken in my VSCode installation, but I don't know how to troubleshoot it. For reference, if I choose another (system) Python interpreter, I get I already reinstalled the The path is most likely from an earlier Python installation, one that I had installed with winget. But where is VSCode taking it from and how can I tell it to stop doing so? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 8 replies
-
I can run my project just fine from the shell (after activating the venv manually first). I just cannot debug it in VSCode. I also have a Jupyter notebook using the same virtualenv, that I'm using out of VSCode. That's also working fine. The problem appears to be limited to Could this file have gotten modified somehow? But wouldn't reinstalling the Python extension reset that file, too? |
Beta Was this translation helpful? Give feedback.
-
I just found out that |
Beta Was this translation helpful? Give feedback.
-
I'm not sure how you installed Python, but I believe that path comes from either the python.org installer of Python or the portable install.
Did you create the virtual environment from the same version of Python you're using to launch the debugger with (you can print out what |
Beta Was this translation helpful? Give feedback.
-
I figured out that if in the This is a fairly simple Flask project. (Sorry that I didn't mention this earlier, it did not seem relevant, as the issue pointed to something with the Python installation.) Now I'm even more confused: is that the solution, or does it just hide an underlying issue? Was this exception for some reason to be expected, and I just got stuck on it, because I had 'stop on all breakpoints' enabled? But I still don't understand why it would raise an exception over this imaginary path... |
Beta Was this translation helpful? Give feedback.
-
Have you figured out why this happened? |
Beta Was this translation helpful? Give feedback.
Ah, that's the key detail. So this is expected because Python's stdlib is "library code", and runpy is raising an exception by doing EAFP-style ("easier to ask forgiveness than permission") programming which is totally legitimate (notice how the line you broke on is in a
try
block).So everything is working as expected, but you're discovering how noisy "stop on all breakpoints" can be when you include code you don't control which may use a coding style which isn't amenable to "stop on all breakpoints".