source venv/bin/activate: Activation Command Reference
Put a virtual environment on PATH for the current shell.
Activation adds a venv bin directory to PATH so "python" and "pip" resolve to that environment. In CI, the catch is that activation only affects the current shell.
Common flags / usage
- . .venv/bin/activate -- Linux/macOS (POSIX shells)
- source .venv/bin/activate -- equivalent long form
- .venv\Scripts\Activate.ps1 -- Windows PowerShell
- deactivate -- leave the environment
Example
shell
# Persist the venv across steps by exporting PATH to GITHUB_ENV:
- run: |
python -m venv .venv
echo "${PWD}/.venv/bin" >> "${GITHUB_PATH}"
- run: pip install -r requirements.txt # uses the venv
- run: pytest # still the venvIn CI
Because each run: block is a fresh shell, "source activate" in one step is gone in the next. On GitHub Actions, append the venv bin directory to GITHUB_PATH once so every later step sees it without re-activating.
Key takeaways
- Activation only changes PATH for the current shell session.
- On GitHub Actions, write the venv bin dir to GITHUB_PATH to persist it across steps.
- Alternatively, call .venv/bin/python and .venv/bin/pip directly.
Related guides
python -m venv: Virtual Environment Command ReferenceReference for python -m venv in CI: creating an isolated environment, options, and a workflow example showing…
python -m pip: Invoke pip Safely Command ReferenceReference for python -m pip in CI: running pip for a specific interpreter to avoid the wrong-pip-on-PATH prob…
uv venv: Fast Virtual Environment Command ReferenceReference for uv venv in CI: creating a virtual environment quickly, pinning the Python version with --python…