Knowledge Base
MilesWeb / How-Tos

How To Install Django Framework?

Approx. read time : 3 min

Django is a very popular framework used for writing Python web applications. It lets you build applications very fast without worrying about the common structural code. This framework lets you focus more on the application, and allow the tools to do the heavy tasks. If you need to install Django on a CentOs7 machine, then there are different methods from which you can choose. 

In this guide, we will get to know the different methods to install Django through pip in Virtual Environment (Virtualenv).

First you need to EPEL repository. The installation methods depend on the EPEL repository for RedHat distributions and CentOS. The EPEL repository consists of the extra packages that are not maintained and are a part of the core distributions.

Installing the EPEL Repository

It’s simple to install the EPEL repository. All you need to do is first configure yum to use the EPEL repository by typing:

You will now get the access to all the applications that are maintained within the EPEL repository.

Let’s see the method to install the Django framework through pip3 in Virtual env:

Django Installation Through pip in Virtualenv

One of the easy way to install Django on your system is through the virtualenv tool. This tool lets you create virtual python environments where you can install any Python packages you want to install without having any effect on the system. This lets you choose the Python packages on your project requirements.

We will first begin by installing pip from the EPEL repository:

Then, install Python and pip using the command given below:

Once pip is installed, you can use it to install the virtual package with the below command:

When you want to start with a new project, you can just create a virtual environment for it. You can start by creating and moving it into a new project directory, by using the command:

Creating New Project in Virtual Environment

This is how you can create new project in virtual environment:

To install packages into the isolated environment, you must first activate the new source project. To do so, type in the below command:

Your command prompt need to reflect that you are in your virtual environment. In your new virtual environment, you can use pip3 to install Django. Make sure you do not use sudo as you are installing it locally.

You can also verify the installation by typing:

To leave the virtual environment, you need to use the deactivate command from thee system:

If you want to work on your project again, you can revert back anytime. All you need to do is, reactivate your virtual environment by moving back into your project directory, and enter command:

After this, you can navigate to the code directory on your Desktop and create asimple helloworld directory with the commands given below:

Then, create a new virtual environment named as, .venv. First activate it, and install Django with Pip3.

Conclusion

This is how you can install Django with Pip3 using the virtual environment. By using a powerful framework like Django, can help to make the web development faster, and let you concentrate on the main aspects of your applications.

Read More: Know How to Deploy Python Django Application?

Nehal Khatri
Nehal is an ardent content writer. She's passionate about crafting content that's simple but adds value. Her insatiable interest in writing has allowed her to explore her skills. She is adept and can write for different types of content formats.