About Lesson
Steps to Add a Virtual Environment in Python
Creating and using a virtual environment is a crucial step in Python development. It helps keep project dependencies isolated, ensuring that different projects don’t interfere with each other. Below is a step-by-step guide to creating and managing a virtual environment in Python 3.12.
1. Install Python (if not already installed)
- First, make sure Python 3.12 (or your desired version) is installed on your system.
- To check if Python is installed, open a terminal or command prompt and run:
PowerShell
python --version
2. Create the Virtual Environment
- Use Python’s built-in
venv
module to create a virtual environment. Run the following command:
PowerShell
c:\digital>python -m venv path/to/your/folder/virtualenvironmentname
Ex- C:\Users\Digital>python -m venv d:/python/learning-python/mypyvenv
3. Activate the Virtual Environment
After creating the virtual environment, you need to activate it.
- On Windows (PowerShell):