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.