Python Programming Fundamentals
Installing Python, IDEs, and Running Scripts
Theory & Concepts
Getting Your Python Environment Ready
Before you can start writing Python code, you need to set up your development environment properly. This lesson will guide you through installing Python, selecting an IDE (Integrated Development Environment), and running your first scripts.
đĄ Welcome!: "This is your first step into programming with Python. Take your time with the installation-a proper setup now will save you hours of troubleshooting later!"
Why Installation Matters
A proper setup ensures:
- Consistency: Your code runs the same way every time
- Efficiency: Good tools make you productive from day one
- Confidence: You know exactly where Python lives and how to access it
- Future-Proofing: Easy to upgrade and manage packages
What You'll Learn
- How to install Python on Windows, macOS, and Linux
- Verifying your Python installation works correctly
- Choosing and setting up the best IDE for beginners
- Running Python in three different ways (shell, scripts, IDE)
- Troubleshooting common installation problems
- Best practices for organizing your Python projects
Installing Python
Python runs on all major operating systems. Follow the instructions for your platform.
Windows Installation
Step-by-Step Guide:
-
Download Python:
- Visit python.org/downloads
- Click "Download Python 3.12" (or latest version)
- Download the Windows installer (64-bit recommended)
-
Run the Installer:
â ī¸ CRITICAL: Before clicking "Install Now", check the box that says "Add Python to PATH". This is the #1 source of installation problems!
- Double-click the downloaded installer
- â Check "Add Python to PATH" (very important!)
- Click "Install Now" for standard installation
- Wait 2-3 minutes for installation to complete
- Click "Close" when finished
-
Verify Installation:
- Press
Windows Key + R, typecmd, press Enter - In Command Prompt, type:
bashpython --version- Expected output:
Python 3.12.0(or your version)
- Press
â Success Check: If you see the Python version, congratulations! Python is installed correctly. If you get an error, see the "Common Pitfalls" section below.
macOS Installation
Step-by-Step Guide:
âšī¸ Note: macOS comes with Python 2.7 pre-installed, but you need Python 3.x for modern development. Don't use the built-in Python 2!
Option 1: Official Installer (Easier)
- Visit python.org/downloads
- Download the macOS installer
- Open the
.pkgfile - Follow the installation wizard
- Enter your password when prompted
Option 2: Homebrew (Recommended for Developers)
Homebrew is a package manager that makes installing tools easier.
-
Install Homebrew (if not installed):
- Open Terminal (Applications â Utilities â Terminal)
- Visit brew.sh and follow instructions
- Or run:
bash/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" -
Install Python via Homebrew:
bashbrew install python3 -
Verify Installation:
bashpython3 --versionExpected:
Python 3.12.0
đĄ Tip: On macOS, always use python3 (not python) to ensure you're using Python 3, not the old Python 2.
Linux Installation
Most Linux distributions include Python, but you may need to install Python 3.
Ubuntu/Debian:
# Update package listsudo apt update# Install Python 3 and pip (package manager)sudo apt install python3 python3-pip python3-venv# Verify installationpython3 --versionFedora/RHEL/CentOS:
# Install Python 3sudo dnf install python3 python3-pip# Verifypython3 --versionArch Linux:
# Install Python 3sudo pacman -S python python-pip# Verifypython --versionâ
Success Check: If python3 --version displays Python 3.8 or higher, you're ready to go!
Choosing an IDE or Code Editor
An IDE (Integrated Development Environment) provides tools to write, run, and debug code efficiently. Here are the best options for Python beginners:
1. VS Code (Highly Recommended for Beginners)
Why VS Code?
- â Free and open-source
- â Lightweight but powerful
- â Excellent Python extension
- â Integrated terminal
- â Auto-completion and IntelliSense
- â Used by professionals worldwide
Installation Steps:
- Download from code.visualstudio.com
- Install VS Code (follow platform-specific instructions)
- Launch VS Code
- Click Extensions icon (left sidebar) or press
Ctrl+Shift+X - Search for "Python"
- Install "Python" extension by Microsoft (has 50M+ downloads)
- Reload VS Code if prompted
First-Time Setup:
- Create a new file:
File â New File - Save it as
hello.py(the .py extension activates Python features) - VS Code will prompt you to select a Python interpreter
- Choose the Python 3.x version you installed
đĄ Tip: VS Code shows the active Python interpreter in the bottom-left corner. Click it to change interpreters if needed.
2. PyCharm Community Edition (Feature-Rich)
Why PyCharm?
- â Purpose-built for Python development
- â Intelligent code completion
- â Powerful built-in debugger
- â Project management
- â Free Community Edition
Installation Steps:
- Download from jetbrains.com/pycharm/download
- Choose "Community Edition" (free)
- Install and launch PyCharm
- Create a new project
- Select Python interpreter (PyCharm auto-detects)
âšī¸ Note: PyCharm is heavier than VS Code but offers more out-of-the-box features. Great if you have a powerful computer and want an all-in-one solution.
3. IDLE (Perfect for Absolute Beginners)
Why IDLE?
- â Comes pre-installed with Python
- â Zero setup required
- â Simple and distraction-free
- â Interactive shell built-in
How to Launch:
- Windows: Search "IDLE" in Start menu
- macOS: Open Terminal, type
idle3 - Linux: Type
idle3oridlein terminal
đĄ Beginner Tip: Start with IDLE to focus on learning Python itself. Once comfortable, graduate to VS Code for professional projects.
4. Jupyter Notebook (For Interactive Learning)
Why Jupyter?
- â Run code in cells (experiment easily)
- â Mix code, text, and visuals
- â Popular in data science
- â Great for tutorials and learning
Installation:
# Install Jupyterpip install jupyter# Launch Jupyter Notebookjupyter notebookâšī¸ Note: Jupyter opens in your web browser. Perfect for learning Python alongside documentation and notes!
Running Python Code - Three Methods
Understanding different ways to run Python helps you work efficiently in various scenarios.
Method 1: Interactive Python Shell (REPL)
The Python shell lets you type code and see results instantly-perfect for learning and experimenting.
How to Access the REPL:
# Windowspython# macOS/Linuxpython3What You'll See:
Python 3.12.0 (main, Oct 2024)Type "help", "copyright", "credits" or "license" for more information.>>>The >>> prompt means Python is waiting for your command.
Try These Examples:
>>> print("Hello, Python!")Hello, Python!>>> 2 + 24>>> name = "Alex">>> print(f"Hello, {name}!")Hello, Alex!>>> # You can use Python as a calculator>>> 15 * 7105>>> # Get help on any function>>> help(print)đĄ Interactive Tip: In the REPL, you don't need print() for single expressions-they display automatically! But always use print() in script files.
Exit the REPL:
- Type
exit()and press Enter - Or press
Ctrl+D(macOS/Linux) orCtrl+Zthen Enter (Windows)
When to Use the REPL:
- â Quick calculations and math
- â Testing syntax you're unsure about
- â Experimenting with new functions
- â Learning Python interactively
Method 2: Running Script Files (.py)
Scripts are files containing Python code that you can run repeatedly. This is how most Python programs work.
Creating Your First Script:
- Create a file called
hello.py:
# hello.py - My first Python scriptprint("Hello, World!")print("Welcome to Python programming!")# Variables work in scripts tooname = "Learner"print(f"Hello, {name}!")# Basic calculationresult = 10 + 5print(f"10 + 5 = {result}")-
Save the file with a
.pyextension -
Navigate to the file's directory:
# Windowscd Documents\PythonProjects# macOS/Linuxcd ~/Documents/PythonProjects- Run the script:
# Windowspython hello.py# macOS/Linuxpython3 hello.pyExpected Output:
Hello, World!Welcome to Python programming!Hello, Learner!10 + 5 = 15â Success! If you see this output, you've successfully run your first Python script!
When to Use Scripts:
- â Programs you want to save and reuse
- â Automation tasks
- â Complete applications
- â Production code
Method 3: Running Code in an IDE
IDEs make running code as simple as clicking a button.
In VS Code:
- Open or create a
.pyfile - Write your code
- Click the âļī¸ (Run) button in the top-right
- Output appears in the integrated terminal
đĄ VS Code Shortcut: Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS), then type "Run Python File"
In PyCharm:
- Open or create a
.pyfile - Write your code
- Right-click anywhere in the file
- Select "Run 'filename'" or press
Shift+F10
In IDLE:
- Create a new file:
File â New File - Write your code
- Save the file (
Ctrl+S) - Press
F5or clickRun â Run Module
When to Use IDE:
- â During active development
- â When using debugging tools
- â Working on large projects
- â Want integrated features (auto-complete, error detection)
Understanding Python Versions
Python 2 vs Python 3
â ī¸ Important: Python 2 reached end-of-life in 2020. Always use Python 3 for new projects!
Key Differences:
- Python 2:
print "Hello"(no parentheses) - Python 3:
print("Hello")(function call)
How to Check Which Version You're Using:
python --versionIf it shows Python 2.x, use python3 instead:
python3 --versionMinor Versions (3.8, 3.9, 3.10, 3.11, 3.12)
Recommendation: Use Python 3.10 or newer for the best features and performance.
Checking Your Version:
import sysprint(f"Python {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")Project Organization Best Practices
Recommended Folder Structure
Documents/âââ PythonProjects/ âââ lesson01/ â âââ hello.py â âââ check_installation.py âââ lesson02/ â âââ variables.py âââ practice/ âââ experiments.pyđĄ Organization Tip: Create a new folder for each lesson or project. This keeps your work organized and makes it easy to find your code later!
Naming Conventions
Python File Names:
- â
Use lowercase:
calculator.py - â
Use underscores for spaces:
student_grades.py - â
Be descriptive:
temperature_converter.py - â Avoid:
Test1.py,new.py,asdf.py
Common Installation Problems & Solutions
Problem 1: "Python is not recognized as a command"
Symptom: When you type python --version in Command Prompt, you get:
'python' is not recognized as an internal or external commandCause: Python wasn't added to your system PATH
Solution (Windows):
- Search for "Environment Variables" in the Start menu
- Click "Environment Variables"
- Under "System variables", find and select "Path"
- Click "Edit"
- Click "New" and add:
C:\Users\YourUsername\AppData\Local\Programs\Python\Python312 - Click "OK" on all windows
- Close and reopen Command Prompt
- Try
python --versionagain
đĄ Quick Fix: Uninstall Python and reinstall, making sure to check "Add Python to PATH" during installation.
Problem 2: "python3: command not found" (macOS/Linux)
Cause: Python 3 isn't installed or uses a different command name
Solution:
# Check if python3 existswhich python3# If not found, install it# macOS:brew install python3# Ubuntu/Debian:sudo apt install python3# Try again:python3 --versionProblem 3: Code Runs But Shows No Output
Cause: Forgot to use print() in your script file
Wrong:
# script.py2 + 2 # This calculates but doesn't displayCorrect:
# script.pyresult = 2 + 2print(result) # Now it displays!âšī¸ Note: In the interactive REPL, expressions display automatically. In script files, always use print() to show output!
Problem 4: "Cannot Find File or Directory"
Cause: Your terminal is in the wrong folder
Solution:
# Find your current locationpwd # macOS/Linuxcd # Windows (shows current directory)# Navigate to your script's locationcd Documents/PythonProjects# List files to verify your script is therels # macOS/Linuxdir # Windows# Now run your scriptpython3 hello.pyđĄ Tip: In VS Code or PyCharm, the terminal automatically opens in your project folder, avoiding this issue entirely!
Quick Reference Commands
Essential Commands
# Check Python versionpython --version # Windowspython3 --version # macOS/Linux# Launch interactive Python shellpython # Windowspython3 # macOS/Linux# Run a Python scriptpython script.py # Windowspython3 script.py # macOS/Linux# Install a packagepip install package_name # Windowspip3 install package_name # macOS/Linux# Upgrade pip (Python's package installer)python -m pip install --upgrade pip # Windowspython3 -m pip install --upgrade pip # macOS/LinuxTerminal Navigation
# Show current directorypwd # macOS/Linuxcd # Windows# Change directorycd folder_name# Go up one levelcd ..# List files in current directoryls # macOS/Linuxdir # WindowsWhat's Next?
Congratulations on setting up Python! Now you're ready to:
- â Write your first Python programs
- â Experiment in the interactive shell
- â Use your IDE's features
- â Start learning Python syntax
â You're Ready!: The hardest part is done. From here on, you can focus entirely on learning Python itself. Everything is set up and working!
Your Next Steps
- Practice running code in all three methods (REPL, scripts, IDE)
- Get familiar with your IDE - explore the features
- Create a project folder to organize your learning
- Move to the next lesson to start writing real Python code!
The setup might feel overwhelming at first, but you only do it once. From now on, it's all about learning to code! đ
Lesson Content
Set up your Python development environment from scratch. Learn how to install Python on Windows, macOS, and Linux, choose the right IDE, and run your first Python scripts with confidence.
Code Example
# ============================================# LESSON 1.1: Installation & Running Scripts# ============================================# This file demonstrates different ways to verify# your Python installation and run code.# ----------------------# 1. VERIFICATION SCRIPT# ----------------------# Save this as: check_installation.py# Run it to verify Python is working correctlyimport sysimport platformprint("=" * 50)print("PYTHON INSTALLATION VERIFICATION")print("=" * 50)# Display Python versionprint(f"Python Version: {sys.version}")print(f"Version Info: {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")# Display system informationprint(f"Operating System: {platform.system()}")print(f"OS Version: {platform.version()}")print(f"Machine Type: {platform.machine()}")# Display Python executable locationprint(f"Python Executable: {sys.executable}")# Test basic functionalityprint("" + "=" * 50)print("BASIC FUNCTIONALITY TEST")print("=" * 50)# Test arithmeticresult = 2 + 2print(f"â Arithmetic works: 2 + 2 = {result}")# Test string manipulationgreeting = "Hello, Python!"print(f"â Strings work: {greeting}")# Test list operationsnumbers = [1, 2, 3, 4, 5]print(f"â Lists work: {numbers}")print(f"â Sum function works: sum = {sum(numbers)}")# Test loopsprint("â Loops work:")for i in range(1, 4): print(f" - Iteration {i}")# Test functionsdef greet(name): """Test function to demonstrate Python is working.""" return f"Welcome, {name}!"print(f"â Functions work: {greet('Learner')}")print("" + "=" * 50)print("â
ALL TESTS PASSED!")print("Your Python installation is working correctly.")print("=" * 50)# ----------------------# 2. HELLO WORLD SCRIPT# ----------------------# The traditional first program# Save as: hello_world.pyprint("--- Hello World Example ---")print("Hello, World!")print("Welcome to Python programming!")# ----------------------# 3. INTERACTIVE SHELL DEMO# ----------------------# Try these commands in the Python REPL (interactive shell):# # >>> print("Hello from the shell!")# >>> 5 + 3# >>> name = "Alex"# >>> print(f"Hi, {name}!")# >>> help(print)# >>> exit()# ----------------------# 4. RUNNING SCRIPTS - PRACTICE# ----------------------# Save this as: my_first_script.py# Then run it using one of these methods:## Method 1 - Command Line:# Windows: python my_first_script.py# macOS/Linux: python3 my_first_script.py## Method 2 - IDE:# - Click the Run button (âļī¸)# - Or press F5## Method 3 - IDLE:# - Open the file in IDLE# - Press F5 or Run â Run Moduleprint("--- Script Execution Example ---")print("This script is running successfully!")print("You can see this output because you executed the .py file.")# ----------------------# 5. PATH DEMONSTRATION# ----------------------# Understanding where Python looks for modulesimport osprint("--- Current Working Directory ---")print(f"Your script is running from: {os.getcwd()}")# ----------------------# 6. MULTIPLE WAYS TO PRINT# ----------------------# All of these display outputprint("--- Different Print Methods ---")# Basic printprint("Method 1: Basic print")# Multiple argumentsprint("Method 2:", "Multiple", "arguments")# f-strings (modern and recommended)language = "Python"version = 3.12print(f"Method 3: I'm learning {language} version {version}")# Concatenationprint("Method 4: " + "String " + "concatenation")# Print with end parameter (no new line)print("Same line", end=" ")print("continued here")# ----------------------# 7. COMMENTS AND DOCUMENTATION# ----------------------# Good code explains itself# This is a single-line commentprint("Comments help explain your code") # Inline comment"""This is a multi-line comment.Also called a docstring when used to document functions.You can write multiple lines of explanation here."""def documented_function(): """ This docstring explains what the function does. Good practice: Always document your functions! """ return "I'm a well-documented function"print(documented_function())# ----------------------# 8. ERROR HANDLING PREVIEW# ----------------------# What happens when something goes wrong?print("--- Error Handling Demo ---")# This will worktry: result = 10 / 2 print(f"Division successful: {result}")except ZeroDivisionError: print("Cannot divide by zero!")# Intentional error handling (uncomment to see error)# try:# result = 10 / 0 # This will cause an error# except ZeroDivisionError:# print("Oops! Cannot divide by zero.")# ----------------------# 9. GETTING INPUT (Preview)# ----------------------# Uncomment these lines to make the script interactive# (Note: Input only works when running as a script, not in interactive mode)# print("--- Interactive Input Demo ---")# user_name = input("What's your name? ")# print(f"Nice to meet you, {user_name}!")# ----------------------# 10. FINAL MESSAGE# ----------------------print("" + "=" * 50)print("đ CONGRATULATIONS!")print("=" * 50)print("You've successfully:")print(" â
Installed Python")print(" â
Set up your development environment")print(" â
Run your first Python script")print("You're ready to start your Python journey!")print("=" * 50)# ----------------------# PRACTICE EXERCISES# ----------------------# Try creating these scripts on your own:## Exercise 1: Create a script that prints your name and age# Exercise 2: Create a script that calculates 23 * 45 and prints the result# Exercise 3: Create a script that prints your favorite quote# Exercise 4: Modify this script to add your own print statements## Remember: Save your files with the .py extension!