There is no activate_this.py file in venv / pyvenv

I need to run venv / pyvenv from a python script, and I know that the official documentation should run:

activate_this = '/path/to/env/bin/activate_this.py' execfile(activate_this, dict(__file__=activate_this)) 

But I do not have activate_this.py file, and I can not find anywhere how to create it.

I am running python 3.4.1. Any idea what I need to do?

+8
python virtualenv
source share
1 answer

As you already noted, the pyvenv / venv does not come with activate_this.py . But if you need this function, you can take activate_this.py from virtualenv , put it in the expected location ( virtualenv_path/bin/activate_this.py ), and then use it. It seems to be working fine. The only problem is that virtualenv docs are deprecated for Python 3 (they claim that you are using an execfile that does not exist). An alternative to Python 3 is:

 activator = 'some/path/to/activate_this.py' # Looted from virtualenv; should not require modification, since it defined relatively with open(activator) as f: exec(f.read(), {'__file__': activator}) 

Nothing activate_this.py is magic, so you can manually make the same changes without manipulating virtualenv (setting PATH , sys.path , sys.prefix , etc.), but borrowing makes it a lot easier in this case.

+5
source share

All Articles