☀️ Columbus 10°C
// How social engineering cost Marks & Spencer £300 Million // The Backdoor (CVE-2024-3094): 500ms Delay that Saved the Internet From Disaster // PostgreSQL Normalization: The Easy Way vs. The Correct Way (1NF, 2NF, 3NF) // SQLite in Depth: Concurrency & Locked Error // How to Restore True Visitor IPs Behind Cloudflare Using NGINX and cf‑nginx (2026) // Understanding Network Layers: Complete Guide to OSI and TCP/IP Models (2026) // Networking Infrastructure: The Complete Guide From Topologies to Security (2026) // Automated Ubuntu VM Creation on Proxmox via Cloud-Init (2026) // Python Virtual Environments (venv) on Windows and Linux (2026) // How to Secure SSH on Debian 11 & 12 with User Creation and Fail2Ban (2026) // How to Set Up an Isolated VM Network in Proxmox with NAT (Step-by-Step) (2026) // How to Configure Locales on Debian (Fix Language and Encoding Issues)
2 min 94

Python Virtual Environments (venv) on Windows and Linux (2026)

Learn how to create and use Python virtual environments to isolate project dependencies, manage packages safely, and avoid conflicts on Linux, macOS, and Windows.

Python Virtual Environments

If you install Python packages globally, things break sooner or later. One project needs a newer version, another needs an older one, and you end up fighting pip instead of writing code. Virtual environments solve this by keeping dependencies local to each project.

This post shows how to set one up and use it in a way that won’t get in your way later.

Install Python and venv

Make sure Python, pip, and the venv module are installed.

Linux (Debian/Ubuntu)

sudo apt update
sudo apt install python3 python3-venv python3-pip -y

Most systems already have Python, but python3-venv is sometimes missing.

Windows

Download and install Python from https://www.python.org/downloads/

During installation:

  • Check “Add Python to PATH”
  • Leave the rest as defaults

Verify installation:

python --versionpip --version

Create a project directory

Keep each project in its own folder. Put the virtual environment inside it.

mkdir -p ~/my_python_project
cd ~/my_python_project

Windows equivalent

mkdir my_python_project
cd my_python_project

The name doesn’t matter. The structure does.

Create the virtual environment

Create a virtual environment called venv:

python3 -m venv venv

Windows

python -m venv venv

This creates a venv/ directory with its own Python and pip. Anything installed here stays here.

Activate the environment

Linux / macOS

source venv/bin/activate

Windows (PowerShell)

venv\Scripts\Activate.ps1

Windows (Command Prompt)

venv\Scripts\activate.bat

You’ll see (venv) in your shell prompt. That’s how you know it’s active.

From this point on, pip install only affects this project.

Install packages

pip install --upgrade pip
pip install flask requests

Install whatever your project needs. It won’t touch system Python.

If you already have a requirements file:

pip install -r requirements.txt

Deactivate when you’re done

deactivate

That’s it. You’re back to the system environment.

Saving dependencies

When the project is in a good state, save the package list:

pip freeze > requirements.txt

To rebuild the environment later:

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Windows rebuild

python -m venv venv
venv\Scripts\Activate.ps1
pip install -r requirements.txt

This works the same on another machine or server.

Important note (Windows only)

If PowerShell blocks activation scripts, run once as admin:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
5 1 vote
Article Rating

Related Posts

SQLite in Depth: Concurrency & Locked Error

SQLite is a powerful, lightweight, and serverless relational database management system (RDBMS) widely used for small to mid-scale projects. Its main strengths lie in its ease of use, minimal configuration, and zero maintenance in most cases.

Ali Eren Tabak Feb 19, 2026
83
5 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments