Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  How-Tos  >  How To Install Django Framework?
Top Scroll

How To Install Django Framework?

 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:

sudo yum install epel-release

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

Check out our Best Django Hosting Plans!

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:

yum install epel-release yum-utils -y

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

yum install python3-pip -y

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

pip3 install Virtualenv

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:

mkdir ~/newproject
cd ~/newproject

Creating New Project in Virtual Environment

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

virtualenv newproject 

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

source newproject/bin/activate 

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.

pip3 install Django

You can also verify the installation by typing:

django-admin –version
3.2.14

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

Deactivate

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:

cd ~/newproject

source newenv/bin/activate

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

# Windows
> cd onedrive\desktop\code
> mkdir helloworld
> cd helloworld

# macOS
% cd ~/desktop/code
% mkdir helloworld
% cd helloworld

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

# Windows
> python -m venv .venv
> .venv\Scripts\Activate.ps1
(.venv) > python -m pip3 install django~=3.2.14

# macOS
% python3 -m venv .venv
% source .venv/bin/activate
(.venv) % python3 -m pip install django~=3.2.14

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?

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.