Simplifying Django dependencies with virtualenv
virtualenv is a tool for simplifying dependency management in Python applications. As the name
virtualenv creates a virtual environment which makes it easy to install Python packages
without needing root privileges to do so.
To use the packages installed in a virtual environment you run the
activate script in the
bin directory of the virtual environment. This is fine when you’re working on the command line, but
you don’t want to have to remember this step when running the debug server, and it’s hard to get that to work
when the site is deployed under
To make things easier you can add the appropriate directory from the virtual environment to Python’s path as
manage.py, or the appropriate
wsgi control script.
import os import sys import siten root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) site.addsitedir(os.path.join(root_dir, 've/lib/python%i.%i/site-packages' % (sys.version_info, sys.version_info)))
Just add the code above to the top of your
manage.py file and the
ve virtual environment
will always be activated when you run the script.