I have to activate the virtual environment (venv) so I running these commands manually in terminal:
source .venv/bin/activate # To activate the virtual env.
and
deactivate # To deactivate the virtual env
This works fine when running manually. Now I have to insert these commands in a bash script to make AWS CodeDeploy to deploy it on a Ubuntu 18.04 server.
My bash script named after_install.sh looks like this...
#!/usr/bin/env bash set -e source .venv/bin/activate ## DO SOME STUFF ## deactivate For local testing, I made the script executable and ran the script using bash after_install.sh. But nothing happened. It doesn't activate the virtual environment. It seems none of the above commands worked while running the bash script.
I am not getting why these commands work when I run them manually but not with a bash script. What is going on? I need to write these commands inside the bash script so that AWS CodeDeploy can deploy it on the server.
It doesn't activate the virtual environment– How exactly do you test this inside the script? My point is:## DO SOME STUFF ##obviously does nothing. I don't know.venv/bin/activate. Does it output anything when sourced interactively? and doesn't output if sourced in a script? Is this your "test"?source .venv/bin/activatemanually it activates your virtual env as it can be seen in the terminal that.venvhas been activated. But when you use the same command inside the bash script it does not activate.venv, seems that the command does not have any effect when running bash script.as it can be seen in the terminal– How exactly? Do you need the environment in the script? Or outside of the script after you "run" it?source .venv/bin/activatethrough a bash script which is not running, as I need the env should get activated after this particular script is executed which is not happening.