Django - How to Install
The page explains how to install Django using a Virtual Environment
Last updated
Was this helpful?
The page explains how to install Django using a Virtual Environment
Last updated
Was this helpful?
Django is a popular framework written in Python used to code modern and secure web applications much faster. Install Django is the first step of this journey and during this short tutorial, we will learn how to properly install Django using a Virtual Environment.
Content Features:
Level: beginners
Mentioned Topics:
Django
Virtual Environment
Basic command-line commands
For newcomers, Django is a popular framework built by experienced developers, actively supported by an impressive open-source community. Django comes with batteries included concept and provides modules to handle the database, authentication, built-in security, plus a powerful command-line interface to interact with our app. To start learning Django feel free to access:
Django - the official website and documentation
Django Introduction - a nice tutorial provided by Mozilla Docs
What is Django - a short introduction provided by AppSeed
A virtual environment helps us to keep isolated the dependencies used by different Python projects. A simple use case
might be this one: we have installed locally two Python apps that use different versions of a common library, Django for instance. Without using a virtual environment the only choice is to install the dependencies in the global environment and this might affect the stability and behavior of both apps.
A virtual environment acts like a sandbox where we can safely install modules with zero effects in the global environment.
Create a new virtual environment
The above commands have identical effects and will create a new env
directory in the current working directory. Once the virtual environment is created, the next step is to run the activation command.
Activate virtual environment
On successful activation, the terminal gets a prefix as below:
The recommended way to install Python packages is to use PIP, the official package manager for Python.
The above command will install the latest Django version. To install a specific version, please use the syntax:
If all goes well, we can check the version using the Python console:
How to uninstall Django or any other pachage
The removal of a Python package can be done with ease via pip
:
At this point, Django is no longer available in our virtual environment.
Once the work is finished, to leave the virtual environment we need to type:
After running deactivate
command, the console prefix should be removed by the terminal:
To learn more about Python, Virtual environments, or get support, please access:
Python - official website
Virtual Environments - official docs