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
Use the terminal figure to recognize the prompt indicator for an active environment. section 2.5.2






