How to install Django using virtualenv

let’s create a virtual environment (also called a virtualenv).

Virtualenv will isolate your Python/Django setup on a per-project basis.

This means that any changes you make to one website won’t affect any others you’re also developing.

For this, we will be using a new directory DhruvPy

$ mkdir DhruvPy
$ cd DhruvPy

We will make a virtualenv called myvenv. The general command will be in the format:

$ python3 -m venv myvenv

Working with virtualenv

The command above will create a directory called myvenv (or whatever name you chose) that contains our virtual environment (basically a bunch of directory and files).

$ source myvenv/bin/activate

You will know that you have virtualenv started when you see that the prompt in your console is prefixed with (myvenv).

Installing Django

Now that you have your virtualenv started, you can install Django.

Before we do that, we should make sure we have the latest version of pip, the software that we use to install Django:

(myvenv) ~$ python -m pip install --upgrade pip

Installing packages with requirements

A requirements file keeps a list of dependencies to be installed using pip install:

In your DhruvPy/requirements.txt the file you should add the following text:


Now, run pip install -r requirements.txt to install Django.

That’s it! You’re now (finally) ready to create a Django application!

Leave a Comment

Your email address will not be published. Required fields are marked *