Web App Dev Logo

Using Django in a
Virtual Environment

OBP Logo

Installing Required Software on Ubuntu / Debian

Creating a Virtual Environment for Your Django App

We recommend one virtual environment for each app, and putting virtual environment inside the project directory. Note that with a default Ubuntu configuration, information on the user and working directory (user@path) will display between to the left of the prompt ($).

  1. $ mkdir mydjangoapp
  2. $ cd mydjangoapp
  3. $ virtualenv --no-site-packages mydjangoappvenv
  4. $ source mydjangoappvenv/bin/activate
  5. (mydjangoappvenv)$ pip install django
  6. (mydjangoappvenv)$ cd ../
  7. (mydjangoappvenv)$ django-admin.py mydjangoapp mydjangoapp

Creating Requirements Files for Your Project

By keeping each Django project in its own virtual environment, you can easily create a text file containing the Python package requirements for it. Here's how: from within the virtual environment for which you want a requirements file, run:

    (mydjangoappvenv)$ pip freeze > requirements.txt

You can use this file to install all the packages you need in a new virtual environment:

    (mynewdjangoappvenv)$ pip install -r requirements.txt