no module named 'django', but django is installed

the server would not start. every run gave the same thing:

ModuleNotFoundError: No module named 'django'

so i installed django. pip said it was already there:

Requirement already satisfied: django in ./venv/lib/python3.12/site-packages

that is where i lost half an hour — reinstalling, rebuilding the venv, checking requirements.txt. pip says installed, python says missing, and both are true. they were not talking about the same python.

comparing the two paths would have ended it in seconds:

pip -V
# pip 24.0 from /path/to/project/venv/lib/python3.12/site-packages/pip

python -c "import sys; print(sys.executable)"
# /usr/bin/python3

different paths means you are done looking. the fix is cmd/ctrl + shift + pPython: Select Interpreter → the one inside the venv.

the general form is worth keeping, because it is not a django thing: a ModuleNotFoundError for a package you just installed is an interpreter mismatch, not a failed install. re-running the install can never fix it, which is exactly why it eats an hour. same bug, different clothes — a jupyter kernel on the base env, python vs python3, a system python shadowing pyenv.

also worth knowing: in vs code the run button and the integrated terminal do not have to agree. you can pip install into an activated venv that the run button never looks at.