Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No activate_this.py file in venv / pyvenv [duplicate]

Tags:

I need to start venv / pyvenv from within a python script and I know the official documentation is to run:

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

But I don't have an activate_this.py file and I can't find anywhere how to create one.

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

like image 296
clifgray Avatar asked Jul 29 '14 16:07

clifgray


1 Answers

As you've noted, pyvenv/the venv module doesn't ship with activate_this.py. But if you need this feature, you can borrow activate_this.py from virtualenv, put it in the expected location (virtualenv_path/bin/activate_this.py), then use it. It seems to work fine. Only issue is that the virtualenv docs are out of date for Python 3 (they claim you use execfile, which doesn't exist). The Python 3 compatible alternative would be:

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

Nothing activate_this.py does is magical, so you could manually perform the same changes without looting from virtualenv (adjusting PATH, sys.path, sys.prefix, etc.), but borrowing makes it much simpler in this case.

like image 127
ShadowRanger Avatar answered Sep 18 '22 19:09

ShadowRanger