How To Install Pip, Django, Virtualenv In Ubuntu


The first thing we have to do before working on a Django web framework is to set up a Django development environment by installing pip, virtualenv, and Django 1.8 LTS(Long Term Support). Today, we will see how this is done on Ubuntu. Since all the Linux based OSs come with pre-installed Python on it with LTS(Long Term Support) version, we should not worry about Python installation. You can check your Python version on ubuntu from the terminal.
To open a terminal in ubuntu, hit Ctrl + Alt + t. This will open your terminal and now type "python" in it to see your Python version.
Steps to for setting up Django Development Environment
First, we need to install pip. Pip is a package management system used to install and manage software packages written in Python. So whenever we will install any package or module we will use command pip to install packageName.
Installing pip in Ubuntu
Open a terminal and write the following command to install pip,
$ sudo apt install python-pip
After installing pip we are required to install virtualenv. What is virtualenv? Virtualenv is a python package to create isolated Python environments. virtualenv creates a folder that contains all the necessary executables to use the packages that a Python project would need.
Installing virtualenv in Ubuntu
Open a terminal and write the following command to install virtualenv,
$ sudo apt install virtualenv
Creating a Virtual Environment
After installing virtualenv we will be creating a virtual environment where all Django projects will be stored. Now go to the directory where you want to store your Django projects. Suppose if you want to store Django projects in the home directory then follow the given steps.
  1. Go to your home directory and create a folder and name it whatever you like, In my case, I have created a folder named venv.
    • Now open terminal and cd into that folder( venv folder ) and type.
      $ cd ven
      $ virtualenv django-venv
      This command will create a folder named django-venv inside your venv folder, you can also change the name of the folder to whatever you want. This django-venv folder will contain the Python executable files and a copy of the pip library which you can use to install other packages. The name of the virtual environment (in this case, it is django-venv) can be anything; omitting the name will place the files in the current directory instead.
Activate your virtual environment
Before installing Django we are required to activate our virtual environment for activating it follow the given steps,
  1. Open terminal type the following command.
    $ source django-venv/bin/activate
    This will activate our virtual environment. Now don’t close your terminal we will be installing Django.
    NOTE - Don’t forget to activate your virtualenv before working on Django.
Installing Django in Ubuntu
We will be installing django 1.8 its the LTS version. The reason to install this version is, there are lots of django modules which do not work well on all the django versions but all the django modules will be working great in LTS version of django, i.e,django==1.8
For installing django 1.8 we will use pip command as django is a python package. So, on the same terminal type the following command,
$ pip install django==1.8
This will install django 1.8. To check if your django has been installed or not type the following command to verify.
On terminal type
$ django-admin help
This will give you all django related commands. This means you have successfully installed django in Ubuntu and our django development environment is ready.