Web Development

Setting up Python Virtual Environments in Django

— 3 min read

Setting up Python Virtual Environments in Django

What is a Virtual Environment?

According to Python's official documentation:

"A virtual environment is a Python environment such that the Python interpreter, libraries and scripts installed into it are isolated from those installed in other virtual environments, and (by default) any libraries installed in a “system” Python, i.e., one which is installed as part of your operating system"

This tutorial assumes that you have python installed in your local machine. For best practices, before you start your django project, start by installing a virtual environment to separate your project packages from locally installed packages. To set up a virtual environment in your django project, run the command:
Windows

python -m venv env
 or
Linux | Mac
python3 -m venv [env]

Where [env] is the name of your virtual environment. Start the virtual environment by running;
Windows
env/Scripts/activate.bat _//In CMD_
env/Scripts/Activate.ps1 _//In Powershell_

or
Linux | Mac
source env/bin/activate