Learn Django

Install & Setup Django

Before we start coding the "Hello, World" application, we need to setup our computer for Django development. This involves creating a working directory, setting up a virtual environment, & finally installing Django. Once those steps are complete you'll be able to build your first web app. Let's get started!

Step 1: Create a Working Directory

You'll need a location to store project files. This can be in any directory on your computer. It's best to place this somewhere you can easily remember and access, like your user directory.

In that folder you'll want to create a directory named hello-world. Open a terminal (Mac) or command prompt (Windows) and execute these commands.

On a Mac

1
2
3
4
5
6
7
8
9
# take note of your directory
$ pwd
/<your_path>/

# create the hello-world directory
$ mkdir hello-world

# change directory
$ cd hello-world

On Windows

1
2
3
4
5
6
7
8
9
# take note of your directory
C:\ echo %cd%
C:\your_path\

# create the hello-world directory
C:\ mkdir hello-world

# change directory
C:\ cd hello-world

Step 2: Create a Virtual Environment

You previously installed the virtualenv tool. This tool allows you to create isolated Python environments on your computer. This is extremely useful because in these virtual environments, we can install software components of any version that don't conflict with other projects we may be working on.

When you create a virtual environment, the tool will create a separate directory in your working folder with a name of your choice. In the step below that name will be venv. That directory will contain the software packages like Python that are used in the environment.

After setting up this directory, it is crucial that you activate the environment before performing any work. By activating the environment you are telling the command prompt/terminal which software packages to reference and where to install new packages.

At the same terminal used in the previous step, execute these commands. These will create the virtualenv and activate it. Remember, anytime you want to use the virtualenv you must activate it again!

On a Mac

1
2
3
4
5
# create the virtual environment
$ virtualenv venv --no-site-packages

# activate the virtual environment
$ source venv/bin/activate

On Windows

1
2
3
4
5
# create the virtual environment
C:\ virtualenv venv --no-site-packages

# Windows: activate the virtual environment
C:\...\crmeasy> venv/Scripts/activate

Step 3: Install Django

With the virtual environment created and activated, we can now install Django. In this step you'll use the Python package manager pip to install Django.

With the same terminal open and virtualenv activated, execute this command.

1
2
3
4
5
6
7
# install Django command
(venv)$ pip install Django==1.7.1
Downloading/unpacking Django==1.7.1
  Downloading Django-1.7.1-py2.py3-none-any.whl (7.4MB): 7.4MB downloaded
Installing collected packages: Django
Successfully installed Django
Cleaning up...

If Django was installed successfully you can move onto the next lesson.

Track your progress with a free account