Initial Setup
Want to start programming in Python? This initial setup guide gets Python installed and working on your system in minutes. By the end, you’ll have Python running and will execute your first program.
This tutorial provides 0-5% coverage - just enough to get Python working on your machine. For deeper learning, continue to Quick Start (5-30% coverage).
Prerequisites
Before installing Python, you need:
- A computer running Windows, macOS, or Linux
- Administrator/sudo access for installation
- A terminal/command prompt
- A text editor (VS Code, Vim, Notepad++, or any editor)
- Basic command-line navigation skills
No prior programming experience required - this guide starts from zero.
Learning Objectives
By the end of this tutorial, you will be able to:
- Install the Python interpreter on your operating system
- Verify that Python is installed correctly and check the version
- Write your first Python program (Hello, World!)
- Execute Python programs using the interpreter
- Manage Python packages with pip
Platform-Specific Installation
Choose your operating system and follow the installation steps.
Windows Installation
Step 1: Download the Installer
- Visit the official Python download page: https://www.python.org/downloads/
- Click Download Python 3.12.X (or latest version)
- Save the installer (e.g.,
python-3.12.X-amd64.exe)
Step 2: Run the Installer
- Double-click the downloaded
.exefile - CRITICAL: Check “Add python.exe to PATH” at the bottom (this is essential!)
- Click Install Now (recommended) or Customize Installation for advanced options
- Wait for installation to complete
- Click Close
Step 3: Verify Installation
Open Command Prompt or PowerShell and run:
python --versionExpected output:
Python 3.12.XAlso check pip (Python package manager):
pip --versionExpected output:
pip 24.X.X from C:\Users\...\Python312\lib\site-packages\pip (python 3.12)Troubleshooting Windows:
- If
python --versionfails, you forgot to check “Add python.exe to PATH” during installation. Reinstall Python and check that box! - If
pythonopens Microsoft Store instead, usepython3orpycommand - Restart Command Prompt after installation to load PATH changes
macOS Installation
Step 1: Check if Python is Pre-installed
macOS includes Python 2.7 (deprecated) and sometimes Python 3. Check:
python3 --versionIf it shows Python 3.8+, you already have Python! But for the latest version, continue below.
Step 2: Download the Package
- Visit https://www.python.org/downloads/
- Click Download Python 3.12.X (macOS installer)
- Download the
.pkgfile:- Universal2: Works on both Intel and Apple Silicon Macs (recommended)
Step 3: Install via Package
- Double-click the downloaded
.pkgfile - Follow the installer:
- Click Continue through the introduction
- Accept the license agreement
- Keep default install location
- Click Install (may require password)
- Click Close when complete
Step 4: Verify Installation
Open Terminal and run:
python3 --versionExpected output:
Python 3.12.XCheck pip:
pip3 --versionExpected output:
pip 24.X.X from /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pip (python 3.12)Alternative: Install via Homebrew
If you use Homebrew, install with:
brew install pythonVerify:
python3 --version
pip3 --versionTroubleshooting macOS:
- Always use
python3(notpython) to avoid running system Python 2.7 - If
python3 --versionshows old version, Homebrew installation takes precedence over system Python - Add Homebrew Python to PATH if needed:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"in~/.zshrc
Linux Installation
Python usually comes pre-installed on Linux, but it may be an older version.
Step 1: Check Current Version
python3 --versionIf it shows Python 3.10+, you’re good! If not, follow the installation steps below.
Step 2: Install via Package Manager
Ubuntu/Debian:
sudo apt update
sudo apt install python3 python3-pip python3-venvFedora/RHEL/CentOS:
sudo dnf install python3 python3-pipArch Linux:
sudo pacman -S python python-pipStep 3: Verify Installation
python3 --version
pip3 --versionExpected output:
Python 3.12.X
pip 24.X.X from /usr/lib/python3/dist-packages/pip (python 3.12)Alternative: Install from Source (Latest Version)
For the absolute latest Python version:
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev \
libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
wget https://www.python.org/ftp/python/3.12.X/Python-3.12.X.tgz
tar -xf Python-3.12.X.tgz
cd Python-3.12.X
./configure --enable-optimizations
make -j $(nproc)
sudo make altinstall # altinstall avoids overwriting system python3Verify:
python3.12 --versionTroubleshooting Linux:
If
python3points to old version, usepython3.12explicitly or update alternatives:sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.12 1Ensure pip is installed:
sudo apt install python3-pip(Ubuntu/Debian)Use
python3andpip3commands (notpythonandpip)
Version Verification
After installation, verify Python is working correctly.
Check Python Version
python --version
python3 --versionYou should see:
Python 3.12.X(Where X is the minor version number)
Check pip Version
pip is Python’s package manager (installs libraries).
pip --version
pip3 --versionExpected output:
pip 24.X.X from <path>/site-packages/pip (python 3.12)Check Installation Path
Find where Python is installed:
where python
which python3This shows the path to the Python executable.
Your First Python Program
Let’s write and run your first Python program - the classic “Hello, World!”.
Create a Project Directory
Create a directory for your Python projects:
mkdir -p ~/python-projects/hello
cd ~/python-projects/helloDirectory structure:
~/python-projects/
└── hello/
└── (we'll create files here)Write the Program
Create a file named hello.py:
print("Hello, World!")That’s it! Python is concise - one line prints text.
Code breakdown:
print(): Built-in function that outputs text to console"Hello, World!": String (text) to print
Save the file as hello.py in your project directory.
Run the Program
Execute your program:
python hello.py
python3 hello.pyOutput:
Hello, World!What happened:
- Python interpreter read
hello.py - Executed the
print()statement - Output appeared in terminal
Interactive Mode (REPL)
Python has an interactive mode (REPL - Read-Eval-Print Loop) for testing code:
python
python3You’ll see the Python prompt:
Python 3.12.X (main, ...)
[GCC ...] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>Try some commands:
>>> print("Hello, World!")
Hello, World!
>>> 2 + 2
4
>>> name = "Python"
>>> f"I'm learning {name}!"
"I'm learning Python!"
>>> exit()Exit interactive mode: Type exit() or press Ctrl+D (Linux/macOS) or Ctrl+Z then Enter (Windows).
More Detailed Example
Let’s write a slightly more complex program. Create greet.py:
name = input("What's your name? ")
print(f"Hello, {name}! Welcome to Python.")
age = int(input("What's your age? "))
print(f"In 10 years, you'll be {age + 10} years old!")Run it:
python greet.py
python3 greet.pyInteraction:
What's your name? Alice
Hello, Alice! Welcome to Python.
What's your age? 25
In 10 years, you'll be 35 years old!Code breakdown:
input(): Gets user input (returns string)f"...": f-string (formatted string) - embeds variables inside{}int(): Converts string to integer for math
Managing Python Packages with pip
pip is Python’s package manager - installs third-party libraries.
Check pip Installation
pip --version
pip3 --versionInstall a Package
Let’s install requests (popular HTTP library):
pip install requests
pip3 install requestsOutput shows download and installation progress:
Collecting requests
Downloading requests-2.31.0-py3-none-any.whl (62 kB)
Installing collected packages: requests
Successfully installed requests-2.31.0List Installed Packages
pip list
pip3 listShows all installed packages:
Package Version
---------- -------
pip 24.X.X
requests 2.31.0
setuptools 69.X.XUse an Installed Package
Create test_requests.py:
import requests
response = requests.get("https://httpbin.org/get")
print(f"Status code: {response.status_code}")
print(response.json())Run it:
python test_requests.py
python3 test_requests.pyOutput shows HTTP response data.
Uninstall a Package
pip uninstall requests
pip3 uninstall requestsConfirm with y when prompted.
Virtual Environments (Best Practice)
Virtual environments isolate project dependencies - prevents conflicts between projects.
Create a Virtual Environment
python -m venv myenv
python3 -m venv myenvThis creates myenv/ directory containing isolated Python environment.
Activate the Virtual Environment
Windows (Command Prompt):
myenv\Scripts\activateWindows (PowerShell):
myenv\Scripts\Activate.ps1(If you get an error about execution policy, run: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser)
macOS/Linux:
source myenv/bin/activateActivated prompt:
(myenv) C:\Users\username\python-projects\hello>(Notice (myenv) prefix - indicates virtual environment is active)
Install Packages in Virtual Environment
With virtual environment activated:
pip install requestsPackages install to myenv/ directory (not system-wide).
Deactivate Virtual Environment
deactivatePrompt returns to normal (no (myenv) prefix).
Why Use Virtual Environments?
Problem without venvs: Project A needs requests==2.28.0, Project B needs requests==2.31.0. Can’t have both system-wide!
Solution with venvs: Each project has its own isolated environment with specific package versions.
Summary
What you’ve accomplished:
- Installed Python interpreter on your operating system
- Verified Python installation with version checks
- Wrote and executed your first Python programs
- Used Python’s interactive REPL mode for experimentation
- Managed packages with pip (install, list, uninstall)
- Created virtual environments for isolated project dependencies
Key commands learned:
python --version/python3 --version- Check Python versionpython hello.py/python3 hello.py- Run Python scriptpython/python3- Enter interactive REPL modepip install <package>- Install a packagepip list- List installed packagespython -m venv <name>- Create virtual environmentactivate/source <name>/bin/activate- Activate virtual environment
Skills gained:
- Platform-specific Python installation
- Running Python scripts and interactive mode
- Package management with pip
- Virtual environment creation and management
Next Steps
Ready to learn Python syntax and concepts?
- Quick Start (5-30% coverage) - Touch all core Python concepts in a fast-paced tour
Want comprehensive fundamentals?
Prefer code-first learning?
- By-Example Tutorial - Learn through heavily annotated examples
Want to understand Python’s design philosophy?
- Overview - Why Python exists and when to use it
Troubleshooting Common Issues
“python: command not found” (Windows)
Problem: Windows can’t find Python command.
Solution:
- During installation, check “Add python.exe to PATH” box
- Reinstall Python if you missed this step
- Or manually add to PATH:
C:\Users\<username>\AppData\Local\Programs\Python\Python312
“python3: command not found” (macOS/Linux)
Problem: System doesn’t recognize python3 command.
Solution:
- Install Python: Follow platform-specific installation steps above
- Ensure installation completed successfully
- Try
pythoninstead ofpython3(some systems link them)
“No module named pip”
Problem: pip is not installed.
Solution:
- Windows: pip installs automatically with Python
- macOS/Linux: Install with
sudo apt install python3-pip(Ubuntu/Debian) or package manager - Verify:
pip3 --versionorpython3 -m pip --version
Virtual environment activation fails (Windows PowerShell)
Problem: PowerShell blocks script execution.
Solution:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserThen try activation again: myenv\Scripts\Activate.ps1
Package installation fails with “Permission denied”
Problem: No write access to system Python directory.
Solution:
- Use virtual environment (recommended): Create venv and install packages there
- Or install with
--userflag:pip install --user <package> - Avoid using
sudo pip(can break system Python)
Multiple Python versions installed
Problem: python --version shows old version.
Solution:
- Use version-specific command:
python3.12 --version - Update PATH to prioritize new Python
- Or use
pylauncher (Windows):py -3.12 --version
Further Resources
Official Python Documentation:
- Python.org - Official Python website
- Python Beginner’s Guide - Official getting started guide
- Python Tutorial - Official comprehensive tutorial
- Python Package Index (PyPI) - Repository of Python packages
Development Tools:
- VS Code with Python extension - Popular editor
- PyCharm - JetBrains IDE for Python
- Jupyter Notebook - Interactive notebook for data science
Community:
- Python Forum - Community help
- /r/learnpython - Reddit beginner community
- Python Discord - Real-time chat for learners