Python venv works, but not from script?

Odd one here. This worked before, but something has changed, perhaps upstream, perhaps in how source or the shell works.

If we go into a directory (lets call it foo) and do a python -m venv venv or virtualenv venv (if installed), the venv directory is created and contains venv/bin/activate. While in this terminal, can do source venv/bin/activate and it works (the python virtual environment is loaded and we get the (venv) prompt.) Then deactivate works.

But if a bash script named start is created here in foo, set executable, and contains source venv/bin/activate, this silently fails and we do not get the (venv) prompt. Tried many combinations of no/relative/full path, no/bash/env bash shebang, etc. It always just silently fails.

This worked awhile ago. Any ideas what changed, and what we can do to start a venv from a script?

Hi @rdtsc

Not really my area, but from what I can tell the fix is to run the script with source instead of executing it directly:

source ./start

or the shorthand:

. ./start

From what I am reading the behavior you are facing is normal.

Hope that helps!