Python Environment Setup
Install Python and set up virtual environments
20-25 minutes
Beginner
Cross-platform
Prerequisites
Before you begin:
- • Administrator access to your system
- • Internet connection for downloading Python
- • At least 2GB of available disk space
- • Windows 10+, macOS 10.15+, or Linux
Installation Steps
Windows Installation
Step 1: Download Python
- Visit the official Python website: python.org
- Click "Downloads" and choose the latest Python version (3.11+ recommended)
- Download the Windows installer (.exe)
Step 2: Install Python
- Run the downloaded installer as Administrator
- Check "Add Python to PATH" (important!)
- Choose "Install Now" for standard installation
- Wait for installation to complete
Step 3: Verify Installation
python --version
pip --version
You should see version numbers for both Python and pip.
macOS Installation
Method 1: Using Homebrew (Recommended)
# Install Homebrew first (if not installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Python
brew install python
Method 2: Official Installer
- Visit python.org
- Download the macOS installer (.pkg)
- Run the installer and follow the wizard
- Verify installation with terminal commands
Linux Installation (Ubuntu/Debian)
Install Python
# Update package list
sudo apt update
# Install Python 3 and pip
sudo apt install python3 python3-pip
Verify Installation
python3 --version
pip3 --version
Setting Up Virtual Environments
Why Virtual Environments?
Virtual environments allow you to create isolated Python environments for different projects, preventing package conflicts.
Create a Virtual Environment
# Create a new virtual environment
python -m venv myproject
# Activate the virtual environment
# On Windows:
myproject\\Scripts\\activate
# On macOS/Linux:
source myproject/bin/activate
You'll know it's activated when you see (myproject)
at the beginning of your command prompt.
Install Packages in Virtual Environment
# Install packages
pip install requests flask pandas
# List installed packages
pip list
# Create requirements.txt
pip freeze > requirements.txt
Deactivate Virtual Environment
deactivate
Verification
Test Your Setup
# Check Python version
python --version
# Test Python with a simple script
python -c "print('Hello from Python!')"
# Test pip
pip --version
If you see version numbers and "Hello from Python!", your installation is successful!
Common Issues & Solutions
'python' is not recognized (Windows)
If you get this error after installation:
- Make sure you checked "Add Python to PATH" during installation
- Restart your command prompt or PowerShell
- Try using
py
instead ofpython
Permission Errors (Linux/macOS)
If you get permission errors when installing packages:
# Use virtual environments instead of global installation
python -m venv myproject
source myproject/bin/activate
pip install package_name
Next Steps
What to do next:
- • Create your first Python script
- • Learn about pip and package management
- • Explore popular Python frameworks (Django, Flask)
- • Set up a development environment with VS Code