Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to deactivate virtualenv from a bash script

I'm a novice in shell scripting, but I want to make a bash script for activate/deactivate a virtual enviroment using virtualenv. Then I want to use this script like a service in Ubuntu copying it inside /etc/init.d folder.

In my script, I have a variable like this: VENV=/opt/odoo/odoo_server/venv_oddo/bin

This variable represents the bin path in my virtual enviroment.

Inside the script, I can activate the virtual enviroment with this statement: . ${VENV}/activate

This is possible because activate is a file inside bin directory in the virtual enviroment.

But I don't know the statement to use in my script to deactivate my virtual enviroment. I can't do this: . ${VENV}/deactivate

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

like image 291
edkalel Avatar asked Apr 09 '15 17:04

edkalel


1 Answers

Just deactivate. It will work in the script as well as in command line, as long as you're using bash.

Edit: also in most cases it is a better idea to spell full python path in your scripts and services. It is stateless, more portable and works pretty much everywhere. So instead of doing

. $VENV/bin/activate
/path/to/my/script.py --parameters

it is usually preferable to do

$VENV/bin/python /path/to/my/script --parameters

Trust me, it will save you debugging time)

like image 159
letitbee Avatar answered Oct 14 '22 13:10

letitbee