Alex Rivera | Logout

How to activate/deactivate a virtualenv from python code?

Asked 2012-07-20T05:13:40.390
10

For activation there is a script that activates a virtualenv from an already running python interpeter using execfile('C:/path/to/virtualev/Scripts/activate_this.py', dict(__file__='C:/path/to/virtualev/Scripts/activate_this.py')). However since I can still import packages that are not in the virtualenv from the current python script I am confused about how it works.
For deactivation there is no python script at all.
What should I do?

Edit
Report

1 Answer

-3

This souds like bad idea. You are trying to modify environment of your script within this script. Please explain why?

Can't you do it hierarchical? Use one script to run different scripts in different virtualenvs.

answered 2012-07-20T05:54:11.760

Your Answer