How to Create a Virtual Environment on Mac
Steps
-
Open Terminal
-
Navigate to your project directory (or where you want the virtual environment to be created):
cd /path/to/your/project -
Create the virtual environment:
python3.12 -m venv pythonclass-py-3.12 python3 -m venv pythonclass-py-3.12
-
Activate the virtual environment:
source pythonclass-py-3.12/bin/activate -
Verify Python version inside the virtual environment:
python --version
-
Install any necessary packages:
pip install -r requirements.txt
-
Deactivate the virtual environment:
deactivate
How to Install Python on Windows
Steps
-
Download the Python Installer:
-
Go to the official Python website:
https://www.python.org/downloads/windows/ -
Click on the latest Python 3.x version (for example, Python 3.12.x).
-
-
Run the Installer:
-
Open the downloaded
.exefile. -
Important: On the first installation screen, check the box that says:
Add Python 3.x to PATH -
Click Install Now to proceed with default settings.
-
-
Wait for Installation to Complete:
-
The installer will install Python and pip (the package manager).
-
Once done, click Close.
-
-
Verify Python Installation:
-
Open Command Prompt (search
cmd). -
Type:
python --version
-
You should see the installed Python version, e.g.,
Python 3.12.x.
-
-
Verify pip Installation:
-
In the same Command Prompt, type:
pip --version
-
This confirms pip is installed and working.
-
Optional: Install Multiple Python Versions and Manage Them
- You can install multiple versions (like 3.10, 3.12) and use tools like py launcher or virtual environments to select which version you want to run.
How to Create a Virtual Environment on Windows
Steps
-
Open Command Prompt or PowerShell
-
Navigate to your project directory (or where you want the virtual environment to be created):
cd C:\path\to\your\project
-
Create the virtual environment:
python3.12 -m venv pythonclass-py-3.12
-
Activate the virtual environment:
- Command Prompt
pythonclass-py-3.12\Scripts\activate.bat
- For PowerShell:
.\pythonclass-py-3.12\Scripts\Activate.ps1
-
Verify Python version inside the virtual environment:
python --version -
Install any necessary packages:
pip install -r requirements.txt -
Deactivate the virtual environment:
deactivate