Django Virtual Environment

Estimated reading: 2 minutes

What is a Virtual Environment?

A virtual environment is a tool used to isolate specific Python environments on a single machine, allowing you to work on multiple projects with different packages and dependencies without affecting each other.

When you create a virtual environment, it creates a copy of the Python executable and the pip package manager and installs them in a new directory. You can then use this copy of Python pip to install packages and manage dependencies for a specific project, without affecting the global Python environment or the packages and dependencies of other projects.

Virtual environments are especially useful when working on multiple projects that require different versions of packages or modules, or when you want to test a package or module in a separate environment before installing it globally.

How to install a Virtual Environment?

Note: Make sure you have Python and pip installed on your machine. If you don’t have these installed, you can follow the instructions for your operating system in the Python documentation here: https://docs.python.org/3/using/index.html

Installing Virtual Environment using pip command

1) Open a terminal window and run the following command to install the virtualenv package:

pip install virtualenv

2) Next Navigate to the directory where you want to create your virtual environment, and run the following command:

virtualenv myenv

3) Replace “myenv” with the desired name for your virtual environment for eg: “virtualenv”. This will create a new directory with the same name as your virtual environment, and install a copy of Python and the pip package manager inside it.

4) You can now activate your virtual environment by running the following command on terminal

source myenv/bin/activate

This will activate virtual environment on your machine

Share this tutorial