Examples


Django - Create Virtual Environment


What is Virtual Environment

  • Virtual environment is a self-contained directory tree that contains a Python installation for a particular version of Python, as well as a number of additional packages.
  • It allows you to work on a specific Django project without affecting other projects or the system-wide Python installation.

Benefits of Virtual Environment

  • If you create your virtual environment inside your project, then each project has its own environment.
  • You don't have to worry about changes to the environment affecting other projects.
  • It helps to managing dependencies and preventing conflicts with system-level Python installations

Install Virutal Environment

If you haven't installed virtualenv, you can use this command:

pip install virtualenv

Create a Virtual Environment

Navigate to your terminal or command to wherein you need to create virtual Environment.And run the following in the command prompt.

D:\django_projects>python -m venv myenv

This will create a folder named myenv (or whatever name you chose) in your project directory, containing a Python interpreter and a Lib folder for libraries.

Activate Virtual Environment

On Windows, Activate the virutal environment, by use the following command

D:\django_projects>myenv\Scripts\activate

Prev Next