Skip to content

VS Code Python Interpreter Reset

VS Code Python Interpreter Reset

Use this when VS Code starts pytest discovery with an interpreter from another project, for example ~/tracker-detector/.venv/bin/python, instead of this repository's local environment.

Symptoms

  • Pytest discovery fails with No module named pytest
  • The Python extension logs an interpreter path from a different workspace
  • The selected interpreter refuses to change even after editing .vscode/settings.json

Why It Happens

This is a VS Code Python extension cache/resolution issue, not an application or developer code issue.

The extension can cache a workspace interpreter separately from the repository settings. In this workspace, pyenv state from another project can also leak in and point VS Code at the wrong virtual environment.

This repository now includes two local fixes:

  • .python-version pins the workspace to Python 3.11
  • venv/ points at the same environment as .venv/ so VS Code can use a non-hidden path

Recovery Steps

  1. Open the project in VS Code.
  2. Run Python: Clear Workspace Interpreter Setting.
  3. Run Python: Clear Cache and Reload Window.
  4. Run Python: Select Interpreter.
  5. Choose /home/paulb/tracker-restapi/venv/bin/python.

If venv/ is missing in your checkout, create it from the repository root:

ln -s .venv venv

Verify The Fix

Run this from the repository root:

venv/bin/python -c "import sys; print(sys.executable); print(sys.prefix)"

You should see both paths resolve inside /home/paulb/tracker-restapi/venv.

Then verify pytest discovery directly:

venv/bin/python -m pytest --version

Notes

  • Do not point VS Code at a different repository's .venv.
  • If the extension still refuses the interpreter after clearing the workspace setting, close VS Code and reopen the folder so it rebuilds the interpreter cache from the local workspace.