Search code examples
pythonvisual-studioenvironment-variablesconfig

Python environment broken in Visual Studio 2022


My Python environment in Visual Studio 2022 is completely broken due to a past misconfiguration, and I try to find ways to debug it.

When I launch Python through PowerShell from desktop, I have no problem.

However, when I launch Python from Visual Studio 2022, it automatically sets the environment variable PYTHONHOME to "C:\Python311," which was an old folder that I deleted and don't use anymore. Due to this, my Python environment is broken across all projects.

I have tried to do the following without success:

  1. Delete PYTHONHOME in both "User" and "System" global system environments.
  2. Delete everything related to C:\Python311 environment in regedit.
  3. Do [System.Environment]::SetEnvironmentVariable("PYTHONHOME", "", [System.EnvironmentVariableTarget]::Machine) in the PowerShell launched from Visual Studio.
  4. Delete any ps1 scripts that could set PYTHONHOME.
  5. Find anything related to PYTHONHOME in C:\Users\username\AppData\Local\Microsoft\VisualStudio
  6. Reinstall Visual Studio with default configuration.
  7. Reset all user config files with devenv.exe /ResetSettings (see here)
  8. Look into the logs (see here).
  9. Be assisted by chatGPT.

My understanding is that Visual Studio uses a misconfigured file defined somewhere in my system when launching Python, which automatically sets PYTHONHOME="C:\Python311". I would like to know where this script file is so that I can reconfigure PYTHONHOME to null. It is not project-specific but global.

If you need more information, please let me know; I will update my question accordingly.


Solution

  • I would have never thought the problem would be in my vsvim config file! I just deleted the following line:

    let $PYTHONHOME = 'C:\Python311'