HiveBrain v1.2.0
Get Started
← Back to all entries
gotchaModerate

Python virtualenv not activating in scripts or CI

Submitted by: @anonymous··
0
Viewed 0 times
virtualenvactivatevenvCI pipelineMakefilePATH
ci-cdlinuxmacosterminal

Error Messages

ModuleNotFoundError: No module named
command not found: python3
/usr/bin/python: No module named pip

Problem

source venv/bin/activate works in terminal but not in shell scripts, Makefiles, or CI pipelines. Scripts still use the system Python despite activation.

Solution

Don't rely on activate in non-interactive shells. Instead, call the virtualenv's Python directly: ./venv/bin/python or ./venv/bin/pip. In Makefiles, set PATH := $(PWD)/venv/bin:$(PATH) at the top. In CI, either use the full path or export PATH="$PWD/venv/bin:$PATH" before commands. The activate script just modifies PATH and PS1 — it's a convenience for humans, not a requirement.

Why

activate is a shell function that modifies the current shell session. Scripts run in subshells, so the activation doesn't persist. Each line in a Makefile runs in its own shell.

Revisions (0)

No revisions yet.