liveBook · Manning

Virtual environment

As explained in Coding with AI

A Python virtual environment is an isolated Python runtime environment with its own interpreter and installed packages, separate from other projects and the system installation.

A Python virtual environment is an isolated runtime for one project, with its own Python interpreter and installed packages. Separating projects prevents package-version conflicts, reduces dependence on globally installed packages, and makes projects more portable. Creating one takes seconds and is a useful habit for projects of any size. section 2.5.2

A practical setup follows this sequence:

  • Open a terminal in the application folder and create an environment with a project-specific name. section 2.5.2 section 4.3
  • Activate the environment before installing packages or developing the application. section 2.5.2 section 4.3
  • Confirm activation by checking for the environment name in parentheses at the terminal prompt. section 4.3
  • Use the appropriate activation command for Linux and macOS or for Windows; Visual Studio Code can provide the terminal. section 4.3

Setting up a project environment

For a project named countwords, create and activate the environment from its folder: `python -m venv countwords`, followed by `source countwords/bin/activate`. On Linux or macOS, a project such as hrpractice can use `python3 -m venv hrpractice` and `source hrpractice/bin/activate`. Windows uses `python -m venv hrpractice` and `.\hrpractice\Scripts\activate`; some systems require an explicit Python path. section 2.5.2 section 4.3

python -m venv countwords

Inspect the command used to create a project-specific Python environment. section 2.5.2

Figure 2.16 A terminal window showing an active Python environment
A picture containing text, screenshot, font, line

Description automatically generated

Use the terminal figure to recognize the prompt indicator for an active environment. section 2.5.2

How Coding with AI covers it

How deep it goes
Explains isolation, package conflicts, activation, prompt verification, and platform commands without detailing environment internals.
Examples
Demonstrates countwords and hrpractice environments through terminal commands, activation prompts, and Linux, macOS, and Windows variants.
What it assumes
Assumes basic terminal use and Python availability while teaching environment creation, activation, and prompt-based verification.
What you can do after
Operate/configure a project-specific Python runtime and verify its activation before developing or installing project packages.
How it connects
Connects Python interpreters with installed packages, global packages, package-version conflicts, project portability, and Flask application development.

Also explained in

Compare how 7 books explain virtual environment →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Coding with AI. The section links point to the parts of the book it draws on.