0Pricing
Python Academy · Lesson

Creating and Activating venv

Create, activate, and deactivate virtual environments with venv.

Creating and Activating venv is a free Python Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Introduction

Python's built-in venv module creates lightweight virtual environments. Activation points your shell to the venv's Python.

Creating a venv

python -m venv .venv creates a virtual environment in the .venv directory.
# Terminal:
# python -m venv .venv
# Creates: .venv/bin/python, .venv/lib/, .venv/pyvenv.cfg
print('create demo')

Activating on macOS/Linux

source .venv/bin/activate changes your shell's PATH to use .venv/bin/python first.
# macOS/Linux:
# source .venv/bin/activate
# Prompt changes to (.venv) user@host...
print('unix activate demo')

Activating on Windows

.venv\Scripts\activate.bat (CMD) or .venv\Scripts\Activate.ps1 (PowerShell).
# Windows CMD:
# .venv\Scripts\activate.bat
# Windows PowerShell:
# .venv\Scripts\Activate.ps1
print('windows activate demo')

Verifying Activation

which python (Unix) or where python (Windows) should point inside .venv/. python --version confirms.
import sys
print(sys.prefix)
# Check if inside venv:
print(sys.prefix != sys.base_prefix)

Deactivating

deactivate returns your shell to the system Python. No harm done — deactivation is safe at any time.
# Terminal:
# deactivate
# Prompt returns to normal
print('deactivate demo')

Installing Packages in venv

After activation, pip install only installs into the venv, not globally.
# (with venv active):
# pip install requests
# pip install flask==3.0.0
print('isolated install demo')

venv Options

--without-pip creates a venv without pip. --copies copies instead of symlinks. --prompt changes the prompt text.
# python -m venv .venv --prompt myproject
# Creates venv with custom prompt: (myproject)
print('venv options demo')

Upgrading pip in venv

Newly created venvs may have old pip. Upgrade: python -m pip install --upgrade pip
# (with venv active):
# python -m pip install --upgrade pip
print('upgrade pip demo')

IDE Integration

VS Code: Ctrl+Shift+P → Python: Select Interpreter → choose .venv. PyCharm auto-detects .venv.
# VS Code settings.json:
# {"python.defaultInterpreterPath": ".venv/bin/python"}
print('ide demo')

Checking venv Status

import sys; sys.prefix != sys.base_prefix checks if a venv is active programmatically.
import sys
in_venv = sys.prefix != sys.base_prefix
print('In venv:', in_venv)

Quick Check

Which command creates a virtual environment in the .venv directory?

Recap

Create: python -m venv .venv. Activate: source .venv/bin/activate (Unix) or Scripts/activate (Windows). Deactivate: deactivate. Install: pip install.

Keep Going

Keep it up! Move on to the next lesson.

Frequently asked questions

Is the “Creating and Activating venv” lesson free?

Yes — the full text of “Creating and Activating venv” is free to read here on the web, and the Python Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO.

What will I learn in “Creating and Activating venv”?

Create, activate, and deactivate virtual environments with venv. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Python Academy?

No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Creating and Activating venv” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Python Academy lesson?

Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Why Virtual Environments Matter
  2. Creating and Activating venv
  3. Managing Dependencies with pip
  4. Modern Tools: pipenv and uv
← Back to Python Academy