I understand how to create a virtualenv, activate that virtualenv, and then install django while the virtualenv is activated. Ex:
virtualenv ~/narnia
source ~/narnia/bin/activate
pip install django
From what I understand, when you “activate” a virtual environment it just changes some path variables while you’re in a shell, nothing more. So when django is installed with pip while narnia is activated, it simply installs things into locations relative to ~/narnia instead of relative to /usr (ex. ~/narnia/lib/python2.6/site-packages instead of /usr/lib/python2.6/site-packages).
And now let’s say I want to create a django project with that virtualenv. I don’t even have to be activated, correct? I could just do:
deactivate
cd ~
narnia/bin/django-admin.py startproject myproject
So, if I have a web server set up with “myproject”…how is that django project tied to the narnia virtualenv at this point? Won’t the system path variables simply be the normal systemwide python paths? How does “myproject” know to use the narnia environment?
I am a little confused on how that works. Any help is appreciated.
Thanks!
Web servers typically have a way to configure their Python use. You can set environment variables, paths, and so on. Use these tools to point to the virtualenv.
For example, in my Apache httpd.conf:
and I have an myapp.wsgi file: