How to Install Django on Different Platform

In this Python Django tutorial, you will learn How to install Django on different Platform.

Where you will also understand about the command pip that is used install and uninstall the python package in Django.

Also you will learn how to create a virtual environment and why it is important. In that virtual environment, you would learn how to install Django.

Then you will understand how to install Django on various platform such as in your terminal, windows, mac and etc.

How to install Django

As Django is a python based web framework, so the first requirement of installing Django is installing python. So, irrespective of any operating system, first we need to install python.

Now, installing python is very easy, you can easily download python from the following official website.

Or you can follow the following article “Python download and Installation steps“. All the steps of installing python in the different operating systems are given in this article.

After installing python, we can easily install the Django framework using PIP. The PIP stands for “Preferred Installer Program” or “Pip Installs Packages” is a recursive acronym for it.

  • It is a package manager for python, and it is mainly used to install, update, uninstall packages. And it comes by default with python version 3.4 or later.
  • But before using PIP to install Django, it is recommended as a best practice to provide a separate environment to each of your Django projects. And we can easily manage the environment using the “venv” module in python.

The “venv” module is used to create a lightweight virtual environment with its own site directories. Now, these directories will be separate from the system site directory.

A virtual environment is a separate independent environment with its own Python binary. So, we can use it to install python packages independently in its site directory.

Next, let’s understand how to create a virtual environment and how to install Django in the different operating systems. Let’s starts with the windows operating system.

Read Python Django length filter

How to install Django in Windows

In this section, you will learn how to create a virtual environment in windows and then how to install Django.

Now, let’s first create a virtual environment using the python venv module. And for this implementation, first, we open a command prompt, and then we need to navigate to the location where we want to create our project.

Now, to create a virtual environment, we can follow the given syntax.

python -m venv environment_name

In the syntax, we need to provide the name of the environment in place of environment_name.

This command will set up the virtual environment and create a directory in the location with the name that we will assign. It is recommended to provide a proper project name for your environment. Here is an example of executing this command.

python -m venv mysite-env

This will create a directory named “mysite-env” in the given location. We can also check for the directory using the “dir” command in the command prompt. This implementation is shown in the following screenshot.

How to install Django in Windows Create Virtual Env

Next, we need to activate the virtual environment by running the activate.bat file which is in the Scripts directory. And for this, we need to follow the following syntax.

environment_name\Scripts\activate.bat

Let’s use this syntax to activate our “mysite-env” environment.

mysite-env\Scripts\activate.bat

This will activate the virtual environment, and we can easily identify this as the environment name will be visible next to the command prompt. The screenshot of this is given below.

How to install Django in Windows Create Activate Virtual Environment

Now, we are ready to install Django, and for this, we will use the PIP. Here is the command to install Django using PIP.

python -m pip install Django

After executing the above command, the latest Django release will be downloaded and installed. In our case, Django-3.2.6 will be installed.

How to install Django in Windows

Read: Python Django vs Flask

How to install Django in Linux / Mac

Now, the steps to install Django in Linux and Mac are the same as there in Windows. The minor difference is in the command for activating the virtual environment. So, in this section, we will understand how we can create a virtual environment and use it to install Django in Linux and Mac operating systems.

Now, to create a virtual environment in Linux or Mac, we can follow the same syntax.

python3 -m venv environment_name

After creating the virtual environment, we need to active it. And for this, we have to use the same command for both Linux and Mac.

source environment_name/bin/activate

By activating the virtual environment, the shell prompt will show the name of the environment which we have activated. Also, it will shift from the system’s python version to virtual environment python.

After this, we can easily use the same pip module to install Django for both Linux and Mac.

python3 -m pip install Django

This will successfully download and install the latest Django release. This is how to install Django in on Linux and Mac system.

Read: ModuleNotFoundError: No module named Django

How to check the Django version

After installing Django in our virtual environment, we can easily check its version. For this, we have to use the following command.

python -m django --version

If we specify Django without its version, then python will automatically download and install the latest Django release. And the latest Django version is 3.2.6.

If we execute the above command, we will get the result in the following way.

How to install Django in Windows Check Django Version

How to install Django in visual studio code

In this section you will learn how to install Django in Visual Studio Code. For installing Django, you have to follow the following given steps.

  • First, we need to install python in our system.
  • Next, start visual studio code, click on the extensions option and install the python extension.
How to install Django in Visual Studio Code Extension
  • Next, in your file system, create a folder to store the virtual environment and the project files.
  • Now, move back to visual studio code, and from the menu bar either select “Terminal“>”New Terminal” or use Ctrl+Shift+` shortcut to open a terminal in VS Code.
  • After this, use the terminal to move to the project location. And then execute either of the following commands to create a virtual environment.
# Linux | macOS
python3 -m venv env_name

# Windows
python -m venv env_name
How to install Django in Visual Studio Code Creating Env
  • Next, open the project folder in VS Code by selecting the “File“>”Open Folder” option from the menu bar. Or, we can also use Ctrl+O shortchut.
  • Now, select “View“>”Command Palette” option from the manu bar to open command palette. Or use Ctrl+Shift+P shortcut. And then, select the “Python: Select Interpreter” command.
How to install Django in Visual Studio Code Activating Env
  • It will open a list of python interpreters that a visual studio can locate. From the list, select the interpreter which is located in the virtual environment which you have created.
How to install Django in Visual Studio Code Selecting Env
  • Now, if we open the terminal in VS code then the virtual environment will be automatically activated.

Note: – if you are using Windows then, you have to change your default terminal from Powershell to command prompt in VS Code. And then start the terminal in VS Code. For this, look for “Terminal>Integrated>Default Profile” in the settings and set it to “Command Prompt“.

  • In the end, simply run the following command in the terminal to install the Django module in your virtual environment.
python -m pip install django
How to install Django in visual studio code

Read: Python Tkinter label

How to install Django in PyCharm

Similar to visual studio code, we can also use PyCharm to install the Django module and create a Django project.

Now, if we are using PyCharm Professional, then we don’t need to install Django separately. A Django project can be created directly in the PyCharm Professional edition.

So, for this article, we will discuss how we can install Django in the PyCharm Community edition. For this, we have to follow the following steps.

  • First, start the PyCharm Community edition and create a new project, and select the “New environment using” option as “Virtualenv“. And click on “Create“.
How to install Django in PyCharm Creating New Project
  • Now, if you are using Windows then you have to change the terminal from PowerShell to the command prompt in PyCharm. For this, go to “Files“>”Settings” and look for Terminal settings under Tools. Now, select shell path from powershell.exe to cmd.exe.
How to install Django in PyCharm Configuring Terminal
  • Now, simply open the terminal in PyCharm and run the following command to install Django.
python -m pip install django
  • It automatically downloads and install the latest Django release in the virtual environment.
How to install Django in PyCharm

Conclusion

So in this Python Django tutorial, you learned How to install Django on various platform, where you installed the Django in Windows, Linux, or Mac. Also learned how to install Django using the IDE such as Visual Studio Code and PyCharm.

You may also like reading the following list of articles.