Skip to content
Latchkey

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 venv

In 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →