I checked the activate script and it looks to me all it does is:
- set VIRTUAL_ENV env
- append $VIRTUAL_ENV/bin in front of PATH
How does virtualenv provide that magical virtual environment by these? What do I miss?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I will describe the basic process, which I learned from the presentation @jcollado linked to.
When Python starts, it looks at the path of the binary, and the prefixes thereof.
So let’s say your virtualenv is
/home/blah/scratch. The Python process knows it was executed from/home/blah/scratch/bin/python(which is usually just a copy of your system python binary/usr/bin/python) and it knows its own versionX.Ybecause it’s compiled into it. Then Python looks forlib/pythonX.Y/os.pyin this order:It stops at
/home/blah/scratch/lib/pythonX.Y/os.pybecause it’s the first file that actually exists. If it didn’t, Python would keep looking. It then setssys.prefixbased on this. It uses a similar process to setsys.exec_prefix, and thensys.pathis constructed based on these.