I want to make shell script that makes virtualenv, activates it, install some libraries and run python script with it.
But I have problem that I can't activate virtualenv in shell script unless i do "source script.sh" but then python3 doesn't work. How can I do something like this?
#!/bin/bash
python3 -m pip install virtualenv
python3 -m virtualenv virtual
source virtual/bin/activate
pip install <some libraries>
python <filename.py>
I would like to do this without any global paths to python. I want it to work locally.
Working with Ubuntu (and most other Linux distros I’d say) it’s safe to use the absolute paths as Python is an essential component of the OS:
If you don’t want to run the systemwide installed Python version, but rather the one first in the calling user’s
PATH
, instead use:Further reading about this alternative