Initial Setup
Want to start programming in Python but not sure where to begin? Installing Python is straightforward, and you’ll run your first program soon. This guide walks you through installation on any operating system and gets you writing code immediately - no programming experience needed.
π― What You’ll Accomplish
By the end of this tutorial, you’ll have:
- β Python installed and verified
- β Your first Python program running
- β Confidence that Python works on your system
π Installation Verification Flow
Here’s the simple path from download to running code:
%% Color Palette: Teal #029E73, Orange #DE8F05
graph TD
A[Download Python from python.org] --> B[Install on Your OS]
B --> C[Verify: python --version]
C --> D{Version Shows?}
D -->|Yes| E[Create hello.py]
D -->|No| F[Check PATH/Restart Terminal]
F --> C
E --> G[Run: python hello.py]
G --> H{Prints Hello World?}
H -->|Yes| I[Success! Python Works]
H -->|No| J[Check File Location]
J --> G
style I fill:#029E73,stroke:#000000,stroke-width:2px
style D fill:#DE8F05,stroke:#000000,stroke-width:2px
style H fill:#DE8F05,stroke:#000000,stroke-width:2px
This diagram shows every verification checkpoint - you’ll know immediately if something’s wrong and where to look.
π Prerequisites
- Basic familiarity with your computer’s terminal/command line
- No programming experience needed
- Internet connection to download Python
After installation, explore the Python Cookbook for practical recipes or start with the Quick Start tutorial to learn core syntax.
πΎ Step 1: Download and Install Python
Windows
- Visit python.org/downloads
- Click the “Download Python 3.x.x” button (latest stable version)
- Run the installer
- CRITICAL: Check “Add Python to PATH” before clicking “Install Now”
- This makes Python accessible from any command prompt
- Without this, you’ll need to manually add Python to your PATH later
- Click “Install Now” and follow the prompts
- Wait for installation to complete
- Close the installer when you see “Setup was successful”
Windows Installation Tips:
- The installer adds Python to
C:\Users\YourName\AppData\Local\Programs\Python\Python3xx\ - If you forget to check “Add to PATH”, you can:
- Rerun the installer and select “Modify”
- Or add manually: Control Panel β System β Advanced β Environment Variables
- Administrator privileges may be required
- Antivirus software might slow down installation
macOS
Option 1: Official Installer (Recommended)
- Visit python.org/downloads
- Choose the appropriate version:
- Apple Silicon (M1/M2/M3): Download universal installer (works for both)
- Intel: Download universal installer
- Run the installer and follow the prompts
Option 2: Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install python
python3 --versionmacOS Installation Tips:
- macOS comes with Python 2.7 pre-installed (deprecated) - ignore it
- Always use
python3command on macOS, notpython - Homebrew Python installs to
/opt/homebrew/bin/python3(Apple Silicon) or/usr/local/bin/python3(Intel) - Official installer includes IDLE (Python IDE) and documentation
- Xcode Command Line Tools might be required for Homebrew
- If you see certificate errors, run
/Applications/Python\ 3.xx/Install\ Certificates.command
Linux
Using package manager (Ubuntu/Debian):
sudo apt update
sudo apt install python3 python3-pip
python3 --versionFor other distributions:
- Fedora/RHEL:
sudo dnf install python3 - Arch:
sudo pacman -S python - openSUSE:
sudo zypper install python3 - Gentoo:
sudo emerge dev-lang/python
Linux Installation Tips:
- Most Linux distributions include Python 3 by default
- Check existing Python:
python3 --version - Install
python3-venvfor virtual environment support (Ubuntu/Debian) - Install
python3-devif you’ll compile Python packages (Ubuntu/Debian) - Use distribution packages for system integration
- Consider
pyenvfor managing multiple Python versions
β Step 2: Verify Installation
Open a new terminal/command prompt and run:
python --version
python3 --versionExpected output:
Python 3.14.2(Version number will vary - Python 3.13.x, 3.14.x are current and supported)
If you get an error:
- “command not found”: Python isn’t in your PATH. Try restarting your terminal.
- On Windows: Re-run installer and check “Add Python to PATH”.
- On macOS/Linux: Python might be installed as
python3only.
π Step 3: Create Your First Program
Create a new file called hello.py using any text editor:
Using a Text Editor:
- Windows: Notepad, Notepad++, VS Code
- macOS: TextEdit (in Plain Text mode), VS Code, Sublime Text
- Linux: nano, vim, gedit, VS Code
Using Command Line:
echo print("Hello, World!") > hello.py
echo 'print("Hello, World!")' > hello.pyFile Contents:
print("Hello, World!")What this means (don’t memorize, just read):
print()- Built-in function that outputs text to the screen"Hello, World!"- A string (text) to be printed- No semicolons, no main function, no imports needed
- Python uses indentation instead of braces
{} .pyextension tells your system this is a Python file
Important: Save as .py file, not .txt. If using Windows Notepad, choose “All Files” in “Save as type” dropdown.
βΆοΈ Step 4: Run Your Program
In the same directory as hello.py:
python hello.py
python3 hello.pyExpected output:
Hello, World!Congratulations! You’ve run your first Python program!
π§ͺ Step 5: Explore the Interactive Shell
Python includes an interactive shell (REPL - Read-Eval-Print Loop) for experimenting:
python
python3You’ll see a prompt like >>>. Try some commands:
>>> print("Hello!")
Hello!
>>> 2 + 2
4
>>> name = "Alice"
>>> print(f"Hello, {name}!")
Hello, Alice!
>>> exit()Type exit() or press Ctrl+D (macOS/Linux) or Ctrl+Z then Enter (Windows) to exit.
The interactive shell is perfect for experimenting - you’ll use it extensively in the Quick Start tutorial and Beginner tutorial.
π¦ Step 6: Verify pip (Package Manager)
Python includes pip, the package installer. Verify it works:
python -m pip --version
python3 -m pip --versionExpected output:
pip 25.3 from /path/to/pip (python 3.14)What is pip?:
- Package installer for Python (pip installs packages)
- Manages third-party libraries from PyPI
- Essential for installing tools like Django, Flask, NumPy, etc.
- Always use
python -m pipinstead of justpipto avoid version conflicts - Comes pre-installed with Python 3.4+
For best practices on managing packages, see Manage Python packages effectively and Use virtual environments.
Common pip commands (you’ll use these later):
python -m pip install package_name
python -m pip list
python -m pip install --upgrade pipβοΈ Verification Checklist
Before moving forward, verify:
-
python --version(orpython3 --version) shows Python 3.13.x or 3.14.x -
python hello.pyprints “Hello, World!” - Interactive shell (
pythonorpython3) starts and responds to commands -
python -m pip --versionshows pip is installed
π You’re Done!
You’ve successfully installed Python and run your first program. You’re ready for the next step.
π What’s Next?
Now that Python is working, choose your learning path:
Quick learner: Python Quick Start
- Learn core syntax and basic patterns in one session
- Understand enough to explore Python independently
- Great for experienced programmers learning Python
Comprehensive learner: Complete Beginner’s Guide to Python
- Comprehensive coverage of Python fundamentals
- Hands-on exercises and practice
- Build a solid foundation for real applications
Problem solver: Python Cookbook
- Jump straight into practical recipes
- Copy-paste-modify approach
- Solutions to common Python tasks
Reference seeker: Python Cheat Sheet
- Quick syntax reference
- Common patterns at a glance
- Perfect for quick lookups
π Troubleshooting
Common Installation Issues
Problem: “python: command not found” after installation
Solution:
- Verify installation completed successfully
- Restart your terminal/command prompt (this refreshes PATH)
- On Windows: Re-run installer and check “Add Python to PATH”
- On macOS/Linux: Try
python3instead ofpython - Verify PATH contains Python:
echo $PATH # macOS/Linux echo %PATH% # Windows
Problem: Multiple Python versions installed
Solution: Verify which Python is in use:
which python3 # macOS/Linux
where python # Windows
python3 --version
python3.11 --version
python3.12 --version
python3.13 --versionUse the specific version command (e.g., python3.12 hello.py) if needed.
Best practice: Use pyenv to manage multiple Python versions cleanly. See also Manage Python versions effectively for detailed guidance.
Problem: “hello.py: file not found” when running
Solution: Ensure you’re in the same directory as hello.py. Check with:
ls # macOS/Linux, shows files in current directory
dir # Windows, shows files in current directory
pwd # Print working directory (both)Navigate to the correct directory:
cd path/to/directory # Change directoryProblem: “Permission denied” when running on macOS/Linux
Solution: You don’t need execute permissions for Python scripts. Run with:
python3 hello.pyNot:
./hello.py # This requires execute permissionsIf you want to run as ./hello.py, add shebang and permissions:
#!/usr/bin/env python3
print("Hello, World!")chmod +x hello.py
./hello.pyProblem: pip not found or outdated
Solution: Upgrade pip:
python -m pip install --upgrade pip
python3 -m pip install --upgrade pipProblem: SSL certificate errors on macOS
Solution: Install certificates:
/Applications/Python\ 3.13/Install\ Certificates.commandThis is common after fresh Python installation on macOS.
Problem: “SyntaxError” when running Python 2 code with Python 3
Solution: Python 3 syntax differs from Python 2. Common differences:
printis a function:print("text")notprint "text"- Division returns float:
5/2 = 2.5not2 - Use Python 3 tutorials and code examples
Platform-Specific Issues
Windows: If Python installed but python command doesn’t work:
- Search for “Edit environment variables” in Start menu
- Click “Environment Variables”
- Find “Path” in System variables
- Add Python installation path (e.g.,
C:\Users\YourName\AppData\Local\Programs\Python\Python313\)
macOS: If Homebrew Python conflicts with system Python:
/opt/homebrew/bin/python3 # Apple Silicon
/usr/local/bin/python3 # IntelLinux: If pip requires sudo:
python3 -m pip install --user package_nameOr use virtual environments (recommended, covered in Quick Start tutorial and Use virtual environments).
Still stuck? Visit Python Documentation or the Python Community Forums. Also check our Python Resources for more learning materials and community links.