Install Python
# Option 1: Microsoft Store (easiest)
# Search "Python 3.12" in Microsoft Store and install
# Option 2: Official installer from python.org
# Download python-3.12.x-amd64.exe
# IMPORTANT: check "Add Python to PATH" during install
# Option 3: winget (package manager)
winget install Python.Python.3.12
# Option 4: Chocolatey
choco install python
# Option 1: Homebrew (recommended)
brew install python@3.12
# Option 2: Official installer
# Download from python.org/downloads/mac-osx/
# Installs to /Library/Frameworks/Python.framework/
# Option 3: pyenv (best for managing multiple versions)
brew install pyenv
pyenv install 3.12.3
pyenv global 3.12.3 # set as default
# Ubuntu / Debian
sudo apt update
sudo apt install python3.12 python3.12-venv python3-pip
# Fedora / RHEL
sudo dnf install python3.12
# From source (any Linux - gives latest version)
sudo apt install build-essential libssl-dev zlib1g-dev
wget https://www.python.org/ftp/python/3.12.3/Python-3.12.3.tgz
tar xf Python-3.12.3.tgz && cd Python-3.12.3
./configure --enable-optimizations
make -j$(nproc) && sudo make altinstall
Verify Installation
# Check Python version
python3 --version # Python 3.12.3
python --version # may be Python 2.x on some systems
py --version # Windows py launcher
# Check pip
python3 -m pip --version # pip 24.0 from ...
# Check where Python is installed
which python3 # /usr/local/bin/python3 (macOS/Linux)
where python # C:\Python312\python.exe (Windows)
# Quick test in terminal
python3 -c "print('Python is working!')"
Virtual Environments
Always create a virtual environment before installing packages for a project. This keeps project dependencies isolated.
# Create a virtual environment in a folder called .venv
python3 -m venv .venv
# Activate it
source .venv/bin/activate # macOS / Linux
.venv\Scripts\activate # Windows PowerShell
.venv\Scripts\activate.bat # Windows CMD
# Prompt changes to show the active venv:
# (.venv) alice@machine:~/project$
# Now install packages - they go into .venv only
pip install requests pandas
# See what is installed
pip list
pip freeze > requirements.txt # save exact versions
# Install from a requirements file
pip install -r requirements.txt
# Deactivate when done
deactivate
Never commit your .venv folder to git - it is large, OS-specific, and reproducible from requirements.txt. Add .venv/ to your .gitignore. Commit requirements.txt (or pyproject.toml) instead so teammates can recreate the environment.
pip Package Manager
# Install a package
pip install requests
pip install requests==2.31.0 # specific version
pip install "requests>=2.28" # minimum version
# Install multiple packages
pip install fastapi uvicorn pydantic
# Upgrade a package
pip install --upgrade requests
# Uninstall
pip uninstall requests
# Search PyPI (or visit pypi.org)
pip search requests # deprecated; use pypi.org instead
# Show package info and location
pip show requests
# List outdated packages
pip list --outdated
# Use python -m pip to ensure the right Python
python3 -m pip install requests # safer than bare 'pip'
VS Code Setup
# Install VS Code extensions (from terminal)
code --install-extension ms-python.python # Python extension (official)
code --install-extension ms-python.pylance # Type checking + autocomplete
code --install-extension ms-python.black-formatter # Auto-formatting
# Or install from VS Code Extensions panel (Ctrl+Shift+X)
# Search: "Python" by Microsoft
# Select interpreter in VS Code:
# Ctrl+Shift+P -> "Python: Select Interpreter"
# Choose your .venv Python (e.g., ./.venv/bin/python)
# settings.json additions for Python
# "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python"
# "[python]": { "editor.formatOnSave": true, "editor.defaultFormatter": "ms-python.black-formatter" }
PyCharm (JetBrains) is the most feature-rich Python IDE - excellent for larger projects with built-in debugger, database tools, and refactoring. The Community edition is free. Jupyter Notebooks (via Jupyter or VS Code) are standard for data science and ML work. IDLE ships with Python and is fine for learning basics.
The Python REPL
The REPL (Read-Eval-Print Loop) lets you run Python interactively. Use it for quick experiments, testing ideas, and exploring objects.
$ python3
Python 3.12.3 (main, Apr 9 2024, 08:09:14)
>>> 2 + 2
4
>>> name = "Alice"
>>> f"Hello, {name}!"
'Hello, Alice!'
>>> # Explore an object's methods
>>> dir([])
['append', 'clear', 'copy', 'count', ...]
>>> # Get help on any object
>>> help(str.split)
>>> # Multi-line input - use ... continuation
>>> def add(a, b):
... return a + b
...
>>> add(3, 4)
7
>>> exit() # or Ctrl+D (macOS/Linux), Ctrl+Z Enter (Windows)
For a better REPL experience, install IPython: pip install ipython. It adds syntax highlighting, auto-completion, magic commands (%timeit, %run), and history search.