How To Install Pip, Django, Virtualenv In Ubuntu

The first thing we have to do before working on django web framework is to setup 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 terminal.

To open 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 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 which contains all the necessary executables to use the packages that a Python project would need.

Installing virtualenv in Ubuntu



Open terminal and write the following command to install virtualenv,

$ sudo apt install virtualenv

Creating Virtual Environment

After installing virtualenv we will be creating a virtual environment where our all django projects will be stored. Now go to the directory where you want to store you django projects. Suppose if you want to store django projects in 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 folder to whatever you want. This django-venv folder will containthe 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 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.

Up Next
    Ebook Download
    View all
    Learn
    View all