Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

Django - Create Virtual Environment


Step 1: Install Python and venv

Ensure that Python is installed on your system. Most Python installations come with the 'venv' module, which is used to create virtual environments. You can check if Python is installed by opening a command-line interface and typing:

python --version


Step 2: Create a Directory for Your Django Project

It's a good practice to create a new directory for your Django project. This helps keep things organized:

mkdir my_django_project
cd my_django_project


Step 3: Create the Virtual Environment

Once you're in the project directory, create a virtual environment. The following command creates a virtual environment named venv in your current directory:

python -m venv venv

This command uses Python to create a virtual environment in a folder named venv.


Step 4: Activate the Virtual Environment

Before installing Django, you need to activate the virtual environment. The activation command depends on your operating system:

venv\Scripts\activate


Step 5: Install Django

With the virtual environment activated, you can now install Django using pip:

pip install django

This command downloads and installs Django and its dependencies into your virtual environment.


Step 6: Verify Django Installation

To confirm that Django is installed, you can run the following command:

django-admin --version

If Django is installed correctly, you should see its version number.


Step 7: Deactivate the Virtual Environment

When you're done working in the virtual environment, you can deactivate it with the following command:

deactivate

This command exits the virtual environment, and your command prompt should return to normal. To reactivate the virtual environment later, use the activation command from Step 4.

With these steps, you've created a virtual environment for Django, installed Django, and learned how to activate and deactivate the environment. Now you can start building your Django project in a clean, isolated workspace without interfering with other Python projects or system settings.


Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java