4 ms·
I think it isn't quite common knowledge that you don't "need" to active a virtual environment to use it. For years, I thought that activating a virtualenv was c
by EE84M3i 5y ago
I think it isn't quite common knowledge that you don't "need" to active a virtual environment to use it. For years, I thought that activating a virtualenv was changing the PATH (so I would get the right binaries in my shell) and another environment variable like PYTHONHOME/PYTHONPATH (so that python would know where to load modules from). It turns out it _only_ sets PATH, which is non-obvious.
As far as I can tell, it turns out that there's some additional magic in the python binary so that it "knows" when it's executed from a symlink to try and add ../lib/pythonX.X/site-packages/ to sys.path, but for the life of me I can't find where this is documented how exactly this works.
- pdonis 5y agoPEP 405 [1], which added virtual environment support to the Python standard library, documents how the python binary attempts to determine sys.prefix, which is the key thing that has to be set to the virtual environment directory in a virtual environment. See the "Specification" section. [1] https://www.python.org/dev/peps/pep-0405/ https://www.python.org/dev/peps/pep-0405/
- EE84M3i 5y agoOh! Thank you! that's incredibly helpful. So, does this mean my understanding of "activate" setting PYTHONHOME (and thus being required for using a virtualenv) was true before this PEP was accepted? Looks like python3.3?
- pdonis 5y ago> does this mean my understanding of "activate" setting PYTHONHOME (and thus being required for using a virtualenv) was true before this PEP was accepted? I believe that's what the activate scripts for third-party virtualenv tools did, yes. > Looks like python3.3? Yes, that's the version for which the PEP was accepted.