What You Need to Get Started
Before writing Python code, you need two things: the Python interpreter (to run your code) and a code editor (to write your code). We will use the official Python distribution and VS Code, which is the most popular setup among developers.
Python 3.11+
The Python interpreter with pip package manager included
VS Code
Free, powerful code editor with excellent Python support
Virtual Environment
Isolated workspace to keep your projects organized
pip Package Manager
Install any of the 400,000+ Python packages
Installing Python
Follow the instructions for your operating system. We recommend Python 3.11 or 3.12 for the best experience.
Windows Installation
Download Python
Visit python.org/downloads and click the big yellow "Download Python 3.x" button
Run the Installer
Double-click the downloaded .exe file to start installation
Verify Installation
Open Command Prompt (search "cmd" in Start Menu) and run:
python --version
pip --version
You should see Python 3.11.x or later and pip version
macOS Installation
Download Python
Visit python.org/downloads and download the macOS installer (choose Intel or Apple Silicon based on your Mac)
Run the Installer
Double-click the .pkg file and follow the installation wizard
Verify Installation
Open Terminal and run:
python3 --version
pip3 --version
Note: On macOS, use python3 instead of python
Linux Installation
Install via Package Manager
Most Linux distributions come with Python. To install the latest version:
Ubuntu/Debian:
sudo apt update
sudo apt install python3.11 python3-pip python3-venv
Fedora:
sudo dnf install python3.11 python3-pip
Verify Installation
python3 --version
pip3 --version
Setting Up VS Code
Visual Studio Code is the most popular code editor for Python development. It is free, fast, and has excellent extensions for Python.
Download VS Code
Visit code.visualstudio.com and download for your operating system
Install Python Extension
Open VS Code and go to Extensions (Ctrl+Shift+X or Cmd+Shift+X)
- Python (by Microsoft) - Essential Python support
- Pylance - Fast IntelliSense and auto-completion
- Python Indent - Fixes Python indentation issues
Select Python Interpreter
Press Ctrl+Shift+P (or Cmd+Shift+P), type "Python: Select Interpreter", and choose your Python installation
Create Your First File
Create a new file, save it as hello.py, and add:
print("Hello, Python!")
Click the Run button (triangle icon) or press F5 to run it!
Virtual Environments
Virtual Environment
An isolated Python environment that keeps project dependencies separate from your system Python installation.
Think of it as a clean room where each project has its own set of tools without affecting others.
Virtual environments are essential for Python development. They prevent package conflicts and keep your projects organized. Here is how to create and use them:
Create a Project Folder
Open terminal and navigate to where you want your project:
mkdir my_python_project
cd my_python_project
Create Virtual Environment
Windows:
python -m venv venv
macOS/Linux:
python3 -m venv venv
This creates a venv folder with a clean Python environment
Activate Virtual Environment
Windows (Command Prompt):
venv\Scripts\activate
Windows (PowerShell):
venv\Scripts\Activate.ps1
macOS/Linux:
source venv/bin/activate
You should see (venv) appear in your terminal prompt
Install Packages
With your virtual environment activated, install packages using pip:
pip install requests
pip install numpy pandas matplotlib
Deactivate When Done
To exit the virtual environment:
deactivate
Running Your First Script
Let us verify everything is working by creating and running a Python script. We will test both basic Python and an installed package.
Test 1: Basic Python
Create a file called test_setup.py with this code:
import sys
print("Python Setup Test")
print("=" * 40)
print(f"Python version: {sys.version}")
print(f"Python path: {sys.executable}")
# Test basic operations
name = input("Enter your name: ")
print(f"Hello, {name}! Your Python setup is working!")
# Test a simple calculation
numbers = [1, 2, 3, 4, 5]
total = sum(numbers)
average = total / len(numbers)
print(f"Sum of {numbers} = {total}")
print(f"Average = {average}")
Run it from the terminal:
python test_setup.py
Test 2: Using pip Packages
First, install the requests library:
pip install requests
Then create test_requests.py:
import requests
# Fetch data from a public API
response = requests.get("https://api.github.com")
print("Testing requests library...")
print(f"Status code: {response.status_code}")
print(f"GitHub API says: Connection successful!")
# Show some response headers
print(f"Content-Type: {response.headers['content-type']}")
If you see "Connection successful!", your pip installation works perfectly!
Common Issues and Solutions
Problem: "python" not recognized
Solution: Python was not added to your system PATH during installation.
- Windows: Reinstall Python and check "Add Python to PATH" option, or manually add it to Environment Variables
- macOS/Linux: Use
python3instead ofpython
Problem: Virtual environment won't activate
Solution: Different activation methods depending on your shell:
- Windows Command Prompt:
venv\Scripts\activate.bat - Windows PowerShell:
venv\Scripts\Activate.ps1(may need to enable scripts first) - macOS/Linux:
source venv/bin/activate
If PowerShell gives an error, run: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Problem: "ModuleNotFoundError" when importing libraries
Solution: Either the library is not installed, or you are not in your virtual environment:
# 1. Make sure venv is activated (you should see (venv) in prompt)
source venv/bin/activate # or venv\Scripts\activate on Windows
# 2. Install the missing library
pip install library-name
# 3. Verify it is installed
pip list | grep library-name
Problem: VS Code can't find Python interpreter
Solution:
- Open Command Palette (Ctrl+Shift+P or Cmd+Shift+P)
- Type "Python: Select Interpreter"
- Look for your virtual environment path (e.g.,
./venv/bin/python) - If not listed, click "Enter interpreter path" and browse to
venv/bin/python(orvenv\Scripts\python.exeon Windows)
Key Takeaways
Python 3.11+
Download from python.org and always check "Add to PATH" during installation
VS Code + Extensions
Install Python and Pylance extensions for the best development experience
Virtual Environments
Always use venv to isolate project dependencies and avoid conflicts
pip Package Manager
Use pip install to add any of 400,000+ packages from PyPI
Command Line Basics
Learn to navigate, activate venv, and run Python scripts from the terminal
Test Your Setup
Always verify your installation by running test scripts before starting a project
Knowledge Check
Test your understanding of Python setup concepts:
Why is it important to check "Add Python to PATH" during installation?
What is the purpose of a virtual environment in Python?
Which command creates a new virtual environment?
How do you activate a virtual environment on Windows (Command Prompt)?
Which command installs a Python package using pip?
What VS Code extension is essential for Python development?