Python virtualenv not activated or interpreter mismatch
April 30, 2026 ยท View on GitHub
Playbook ID: python-virtualenv-not-activated
Category: build
Severity: medium
Tags: python, virtualenv, venv, interpreter, environment
What this failure means
Python code is using a system interpreter or wrong virtualenv instead of the activated one, causing module import failures or version mismatches.
Common log signals
activate: not found
source.*venv
/usr/bin/python.*No module named
venv/bin/activate
site-packages from system Python
Diagnosis
When a Python virtualenv is not activated or is deactivated mid-build, pip and modules are installed in the wrong location. Common causes:
- The virtualenv activation step (e.g.,
source venv/bin/activate) was skipped or failed silently - The build runs multiple shell invocations without persisting the activation across steps
- The script uses
#!/usr/bin/env pythonwhich may resolve to the system interpreter, not the virtualenv one - GitHub Actions or other CI steps start with a fresh shell that needs re-activation
Symptoms include ModuleNotFoundError for packages that were installed, or import failures from the wrong Python version.
Fix steps
-
Create and activate the virtualenv explicitly in your CI build script:
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt python -m pytest -
If using GitHub Actions, use
actions/setup-pythonto manage the virtualenv:- uses: actions/setup-python@v4 with: python-version: '3.11' cache: 'pip' - run: pip install -r requirements.txt - run: python -m pytest -
If running multiple steps, either source the activation in each step or use a single shell script:
- run: | source venv/bin/activate pip install -r requirements.txt python -m pytest -
Verify the correct Python interpreter is in use:
which python3 python3 --version
Validation
which python3shows the path inside the virtualenv, not the system Python.python3 -c "import sys; print(sys.prefix)"shows the virtualenv directory.pip listshows the packages fromrequirements.txt.- Re-run the test or build command successfully.
Likely files to inspect
requirements.txtsetup.pypyproject.toml.github/workflows/*.yml.gitlab-ci.yml
Run Faultline
faultline analyze build.log
faultline explain python-virtualenv-not-activated
faultline workflow build.log --json --mode agent
Search phrases this page answers
- Python virtualenv not activated or interpreter mismatch
- Build: python virtualenv not activated or interpreter mismatch
- /usr/bin/python.*No module named
- GitHub Actions python virtualenv not activated or interpreter mismatch
- faultline explain python-virtualenv-not-activated
- Python python virtualenv not activated or interpreter mismatch
Generated from playbooks/bundled/log/build/python-virtualenv-not-activated.yaml. Do not edit directly โ run make docs-generate.