Search code examples
pythonpython-3.xvisual-studio-codedebuggingpython-venv

Virtual environments for Python not working in VSCode


I use the VSCode debugger for all of my Python projects extensively. But for one of my projects, the debugger just doesn't work.

Whenever I try to debug something, it seemingly tries to activate the virtual environment. Then, the debugger just hangs until failure.

debugger hanging

For any other project of mine, using debug with files, or modules, or whatever other options there are for Python, works fine. For this specific project, it has this awkward behavior.

I've tried:

  • Running it over and over again.
  • Completely deleting the folder and recloning the repository with Git
  • Using a completely new launch.json.
  • Reinstalling all Python extensions, and switching to pre-releases.
  • Restarting my computer.
  • Emptying ~/.zshrc.
  • Deleting every single file in the directory except for a single testing start.py, and running that. The error persists.
  • Making sure all my dependencies are functioning, and successfully running the file I want to run with python on the CLI.

Nothing has worked.

Every other project I have tested works fine. It seems the only delimiting factor of the issue is, absurdly, the name of the folder from which I run the code in. (This paragraph is wrong; I was being obtuse. I've edited below to line out what the real delimiting factor was).

Edit: I have finally gotten the project to work by not using a virtual environment. Upon further testing, other projects have the same issue when using a virtual environment.

I've never had this issue before with virtual environments, so I don't know why it's acting up now. While the issue has been narrowed down, my problems persist as I need a virtual environment for my project.


Solution

  • Turns out the fix was manually copying the command VSCode runs to debug, and running it in the integrated terminal manually.

    This worked for debugging it once, and the entire system fixed itself somehow after.

    I have no idea why, or what was happening originally. This seems like a bug still, however it is "resolved."