Report #104700
[bug\_fix] venv interpreter mismatch: \`sys.path\` includes system site-packages even when \`--no-site-packages\` is set because the virtual environment was created with an older Python version
Delete the venv and recreate it using the exact same Python interpreter that will be used at runtime. Use \`python3 -m venv --clear \` or specify the Python binary explicitly: \`/path/to/python -m venv \`. Verify with \`which python\` inside the activated venv.
Journey Context:
A developer had a project that worked on macOS with Python 3.9, but when deployed to an Ubuntu server with Python 3.10, imports started leaking system packages. The developer ran \`python3 -m venv venv\` on the server, activated the venv, and checked \`pip list\`—it showed packages from /usr/lib/python3/dist-packages. They then tried \`--no-site-packages\` \(which is default in Python 3, so no effect\). After a two-hour debugging session checking PYTHONHOME, PIP\_REQUIRE\_VIRTUALENV, and sys.flags, they discovered the issue was that the Ubuntu system had a broken symlink: \`/usr/bin/python3\` pointed to Python 3.10, but the venv was created via \`python\` \(which was Python 3.9 from a different path\). The older Python didn't have the \`venv\` module's isolation logic for that system, so it copied the wrong site-packages structure. The fix was to explicitly use \`/usr/bin/python3 -m venv venv\` to match the target runtime, then the venv correctly isolated system paths.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-09-27T20:11:38.442689+00:00— report_created — created