This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pyvenv activate_this.py
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Attila-Mihaly Balazs, couplewavylines, vinay.sajip
Priority: normal Keywords:

Created on 2014-05-13 13:52 by couplewavylines, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg218455 - (view) Author: (couplewavylines) Date: 2014-05-13 13:52
Is there any plan to add an 'activate_this.py' to venv? The virtualenv package includes this script. Its purpose is to activate the environment "in-place," from other Python code.
One use-case is running multiple WSGI apps that each need a different virtual environment: https://www.pythonanywhere.com/wiki/VirtualEnvForNewerDjango
msg218489 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2014-05-13 22:43
You say "from other Python code", but you mean running an external command in a subprocess, right? If you know where that command is (which you would need to in order to invoke activate_this on the appropriate venv) then you could run the command directly from its bin folder in the venv, and it would run with the venv's environment (interpreter, sys.path etc.)
msg218526 - (view) Author: (couplewavylines) Date: 2014-05-14 13:17
"run the command directly...would run with the venv's environment":  I'm sorry I didn't realize this, the "You don’t specifically need to activate an environment..." part of the venv docs didn't sink in for me when I read it earlier.

So yes, using a subprocess will do what I'm after.

I don't know if the subprocess will cover the situation in that link where they're using execfile on activate_this, but I was just trying to find a common-looking use-case for activate_this.
msg218530 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2014-05-14 13:55
Okay, I'll close this issue.
msg269928 - (view) Author: Attila-Mihaly Balazs (Attila-Mihaly Balazs) Date: 2016-07-07 10:07
Hello,

A scenario where this would be needed (and where you can't just "execute the script with the python from inside the pyvenv" to get it automatically activate) is when running under mod_wsgi. There sometimes it is needed to activate the virtualenv "on the fly" from inside the application.wsgi.

Just taking activate_this.py from virtualenv and dropping it into env/bin seems to work nicely, so perhaps that could become the official solution?
History
Date User Action Args
2022-04-11 14:58:03adminsetgithub: 65695
2016-07-07 10:07:59Attila-Mihaly Balazssetnosy: + Attila-Mihaly Balazs
messages: + msg269928
2014-05-14 13:55:02vinay.sajipsetstatus: open -> closed
resolution: not a bug
messages: + msg218530
2014-05-14 13:17:14couplewavylinessetmessages: + msg218526
2014-05-13 22:43:32vinay.sajipsetmessages: + msg218489
2014-05-13 20:41:52ned.deilysetnosy: + vinay.sajip
2014-05-13 13:52:49couplewavylinescreate