Virtual Environments

Python - A Quick Start for existing Programers

2 min read

Published Sep 16 2025, updated Sep 30 2025


21
0
0
0

Python

A virtual environment is a self-contained directory that isolates a Python interpreter and its packages from the global Python installation. This lets you work on different projects without conflicts between package versions.




Why Use Virtual Environments?

  1. Dependency isolation - Each project can have its own packages and versions, avoiding conflicts.
  2. Avoid polluting global Python - Keeps your system Python clean and avoids breaking system tools.
  3. Reproducible environments - Makes it easier to share projects; you can create a requirements.txt to replicate the environment elsewhere.
  4. Supports multiple Python versions - You can use different Python interpreters for different projects.



How to Set Up a Virtual Environment

# Create a virtual environment called '.venv'
python3 -m venv .venv

# Activate it (Linux/macOS)
source .venv/bin/activate
# or activate it (Windows CMD)
.venv\Scripts\activate
# or activate it (Windows PowerShell)
.\.venv\Scripts\Activate.ps1

# Your shell prompt should change to indicate the environment is active
# e.g., (.venv) $

Make sure the virtual environment folder is added to your .gitignore file so that environment packages aren't included in your repository.


Install any packages required as normal, these will now be stored locally in the virtual environment and only available to that project, not globally, eg:

pip install numpy

To detail which packages are required for a project, you can create a requirements.txt list, to record what packages are required and to easily install them, which is useful when sharing a project with others.


Create the requirements.txt file with:

pip freeze > requirements.txt

Install all packages in requirements.txt with:

pip install -r requirements.txt

Returns you to the system Python environment:

deactivate

Products from our shop

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Mug

Docker Cheat Sheet Mug

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Mug

Vim Cheat Sheet Mug

SimpleSteps.guide branded Travel Mug

SimpleSteps.guide branded Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - Black

Developer Excuse Javascript Mug - Black

SimpleSteps.guide branded stainless steel water bottle

SimpleSteps.guide branded stainless steel water bottle

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Dark

Developer Excuse Javascript Hoodie - Dark

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact