Python virtual environments allows you load all of the dependencies a project may have into its own isolated environment. This means that if you have multiple projects with different versions of dependencies or wish to move your environment to a different location for example production. You will only need to move the dependencies required.

To setup a virtual environment perform the following steps:

  1. Ensure the Virtual Environments module is installed.
    pip install virtualenv
  2. To create a new virtual environment run the following command
    python -m venv C:\Scripts\project_Name\venv
  3. To activate the virtual environment navigate into the venv/Scripts folder created by the step above and execute activate
    activate
  4. To deactivate the environment simply type deactivate
    deactivate
  5. To export a list of requirements from your environment
    pip freeze --local > requirements.txt
  6. To install the exported requirements file
    pip install -r requirements.txt