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?
Asked
Active
Viewed 6,415 times
10

the_drow
- 18,571
- 25
- 126
- 193
-
I don't understand what you mean by deactivation. if you don't want the virtualenv.. just delete that whole folder. that's all – Surya Jul 20 '12 at 05:52
-
when we write programs in editor (say eclipse).. there python path is by default not the virtualenv.. so, you are able to use packages that are not in virtualenv. that's it – Surya Jul 20 '12 at 05:53
-
1@Surya When deactivating a virtualenv it means that you are returning to the main python interpeter. – the_drow Jul 21 '12 at 08:44
4 Answers
6
From part of the VirtualEnv homepage.
You must use the custom Python interpreter to install libraries. But to use libraries, you just have to be sure the path is correct. A script is available to correct the path. You can setup the environment like:
activate_this = '/path/to/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

brechin
- 569
- 4
- 7
-
-
2@Pieter http://stackoverflow.com/questions/436198/what-is-an-alternative-to-execfile-in-python-3-0 – satoru Aug 27 '15 at 03:01
0
If you want to run a program outside of the virtualenv, just run your system python executable (e.g. /usr/bin/python
) instead of the one in the virtualenv.

Max
- 1,620
- 15
- 22
-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.

Tomasz Wysocki
- 11,170
- 6
- 47
- 62
-
1I am developing a test runner like tox (only very different in it's approach. I am not reinventing the wheel) that runs the test suite under different virtual environments using different dependencies and python interpeters. Therefor, I must have a programmatic way to activate and deactivate virtualenvs. – the_drow Jul 21 '12 at 08:47