Punter Vicky
Punter Vicky

Reputation: 17032

virtualenv not active when run from a shell script

When I run source venv/bin/activate in command line , it activates the virtualenv. However when run this via a shell script ./run.sh , I don't see the virtualenv being activated. Similar scripts used to work for me in the past , however I am not sure what I am missing now. I am running this is on a mac.

#! /bin/bash
source venv/bin/activate

(venv) 8c859072374671e:my-project tee78$

Upvotes: 3

Views: 836

Answers (1)

han solo
han solo

Reputation: 6600

When you are running source inside a script. It is running in a new environment. It won't get reflected in the parent shell.

$ cat run.sh
#! /bin/bash
source venv/bin/activate

It you need that to happen do, source your script,

source run.sh

Also, you won't need the shebang line :)

Upvotes: 5

Related Questions