python - how to deactivate virtualenv from a bash script -


i'm novice in shell scripting, want make bash script activate/deactivate virtual enviroment using virtualenv. want use script service in ubuntu copying inside /etc/init.d folder.

in script, have variable this: venv=/opt/odoo/odoo_server/venv_oddo/bin

this variable represents bin path in virtual enviroment.

inside script, can activate virtual enviroment statement: . ${venv}/activate

this possible because activate file inside bin directory in virtual enviroment.

but don't know statement use in script deactivate virtual enviroment. can't this: . ${venv}/deactivate

the problem doesn't exist file named deactivate, deactivated function inside bin/activate file in virtual enviroment.

it'll hard make service useful.

. ${venv}/activate # note dot 

or

source ${venv}/activate 

will source activate script, i.e. run contents as if part of shell or script source them. virtualenvironment's activate is designed usage. in contrast, executing script with

${venv}/activate # note: no dot , no 'source' command 

will run content in subshell , won't have useful effect.

however, service script run in subshell of own. except python commands run part of service start process, won't have effect.

on plus side, won't have care de-activating environment, unless want run more python stuff in service start process, outside of virtualenv.


Popular posts from this blog