Creating and Using Virtual Environments in Python
18 February 2025

Vitrual environments are essential for managing deprendencies in Python projects, ensuring that
ensuring that each project operates independently with its own set of packages.
1. Creating a Virtual Environment
To create a virtual environment, use the following command:
python -m venv environment_name
2. Activating the Virtual Environment
- Windows:
environment_name\Scripts\activate
- macOS/Linux:
source environment_name/bin/activate
3. Installing Packages in a Virtual Environment
Once activated, install required packages using:
pip install package_name
4. Deactivating the Virtual Environment
To exit the virtual environment, use:
deactivate
5. Removing a Virtual Environment
To delete an existing virtual environment, simply remove its directory:
rm -rf environment_name # macOS/Linux
rmdir /s environment_name # Windows (PowerShell)
Using virtual environmentensure project isolation, prevents dependency conflicts, and enhances project portability.