I was adding a small Python script to batch-tidy wallpaper images one evening. pip install had succeeded, the script ran fine in the terminal, and yet every import in the editor kept its red squiggle. No autocomplete either.
What I'd like to say up front is that this is almost always a mismatch between the Python your terminal uses and the Python your editor is looking at. I didn't see that at first. I reinstalled packages, rebuilt the environment, and spent about half an hour circling the same spot. It didn't go well.
First, put the two Pythons side by side
Before changing anything, check whether they actually differ. In the terminal:
which python # where python on Windows
python -c "import sys; print(sys.executable)"
python --versionThen click the Python version in Antigravity's bottom-right status bar. The path of the selected interpreter should be visible.
- The paths match: the interpreter is selected correctly, and the cause is elsewhere (see "If it still won't clear" below).
- The paths differ: the editor is looking at a different Python, and the steps below apply.
Compare the path string, not the version number. Two 3.12 installs, one system-wide and one inside .venv, can hold completely different packages.
venv
For an environment created with python -m venv .venv at the project root, the interpreter lives here:
- Mac / Linux:
.venv/bin/python - Windows:
.venv\Scripts\python.exe
Open the command palette (Cmd+Shift+P / Ctrl+Shift+P) and run "Python: Select Interpreter". If .venv is listed, pick it; if not, choose "Enter interpreter path" and paste the path above.
# create at the project root
python -m venv .venv
# activate
source .venv/bin/activate # Mac/Linux
.venv\Scripts\activate # Windows
# confirm
which pythonMenu wording shifts a little between extension versions. If you can't find the entry, typing "interpreter" into the palette narrows it down.
Poetry
By default Poetry creates environments in a cache directory under your home folder (on a Mac, ~/Library/Caches/pypoetry/virtualenvs/). Because they live outside the project, auto-detection can miss them.
# have Poetry create the environment inside the project as .venv
poetry config virtualenvs.in-project true
# rebuild the existing environment
poetry env remove python
poetry installAfter that, .venv sits at the project root and is picked up like any plain venv. If you'd rather keep the cache location, run poetry env info --path, append /bin/python to what it prints, and enter that as the interpreter path.
uv
uv creates .venv inside the project by default, so it's usually detected without fuss. Right after uv sync, though, the editor can lag behind.
uv sync
uv run python -c "import sys; print(sys.executable)"Compare that output with the status-bar path. If they differ, select the interpreter again. If packages go missing after uv add, this uv package-not-found fix covers that side.
Conda
Conda environments seem harder to auto-detect than venvs. Start by finding where the environment actually is:
conda info --envs
# myenv /opt/homebrew/Caskroom/miniconda/base/envs/myenvAppend /bin/python to that path and enter it as the interpreter. If re-selecting every time gets tedious, you can record it in the project's .vscode/settings.json (Antigravity reads VS Code–style settings):
{
"python.defaultInterpreterPath": "/opt/homebrew/Caskroom/miniconda/base/envs/myenv/bin/python"
}That's a path on your machine, though. If the repository is shared, either add the file to .gitignore or expect each person to edit it, so it doesn't break on someone else's setup.
When activate fails on Windows
In PowerShell, .venv\Scripts\activate can stop with an error saying that running scripts is disabled on this system. It looks like a virtual environment problem, but the cause is PowerShell's execution policy.
# Check the current policy
Get-ExecutionPolicy -Scope CurrentUser
# Allow locally written scripts for your user only
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSignedI keep the scope at CurrentUser, so nothing machine-wide gets loosened. This fixes "the terminal can't activate," which is a separate matter from the editor's interpreter selection. Once activate works, I still compare the two paths from the first section.
When .venv is missing from the interpreter list
Sometimes "Select Interpreter" opens and the .venv you just made isn't in the list. I assumed the environment was broken and rebuilt it. That didn't go well. The environment was fine; the editor simply hadn't noticed it.
Check whether the environment is real first:
ls .venv/bin/python # dir .venv\Scripts\python.exe on Windows
cat .venv/pyvenv.cfgIf pyvenv.cfg is readable and its home = line points at an existing Python, the environment is alive. Don't rebuild it; choose "Enter interpreter path" and give it .venv/bin/python directly, which settles it on the spot.
The case that does call for a rebuild is when the Python named in home = has since been uninstalled or upgraded through Homebrew, leaving the .venv pointing at nothing.
Open pyvenv.cfg and read it before deciding an environment is broken. Rebuilding is the last resort, not the first move.
If it still won't clear
When the paths match but the red squiggles stay, check these four in order.
1. The window was never reloaded. If you created the environment after launching, the editor is still holding its old list. Run "Developer: Reload Window" from the palette.
2. The opened folder isn't the project root. If you opened only a subfolder, .venv can fall outside the search scope. Reopen the folder that contains pyproject.toml or requirements.txt.
3. Terminal activation and editor selection are separate things. Running activate in a terminal doesn't change the editor's interpreter, and selecting one in the editor doesn't switch terminals that are already open. Opening a fresh terminal brings them back in line.
4. The language server remembers the old state. Right after switching interpreters, Pylance or a similar server can keep pointing at the previous environment. If Reload Window doesn't clear it, restart the extension.
I rebuilt the environment twice before reaching the fourth item. Looking back, the first step, comparing the paths, would have been enough.
Line the two paths up first, and fix nothing until you've seen them disagree. I try to keep that order even on days when I'm in a hurry.
When a team needs the same setup
Per-person path differences survive however tidy your settings file is. If you want the Python version and environment pinned together, a DevContainer is the shorter route; I wrote the steps in the DevContainer setup guide. If a similar mismatch is showing up on the Node.js side, this Node version mismatch note may help.
One thing to do next
In the project you have open right now, compare the status-bar path with the output of which python. It takes under a minute, and it settles about half of these cases on the spot.