Home/Blog/Python/Mac Python Setup Guide | Install and Configure Python Development Environment
Python

Mac Python Setup Guide | Install and Configure Python Development Environment

Install Python, Xcode, Homebrew, and VS Code on macOS. Complete guide for setting up a professional Python development environment.

Mac Python Setup Guide | Install and Configure Python Development Environment

Step 1: Launch Terminal

The Terminal is macOS’s command-line interface, similar to Unix/Linux CLI environments since macOS is based on BSD Unix. It’s your gateway to installing development tools and managing your Python environment.

How to Access Terminal

  • Press Cmd + Space to open Spotlight search
  • Type “Terminal” and press Enter
  • Or go to Applications → Utilities → Terminal

💡 Pro Tip: Pin Terminal to your Dock for quick access. Right-click the Terminal icon in your Dock and select “Options → Keep in Dock”.

Step 2: Install Xcode Command Line Tools

Xcode Command Line Tools provides essential development utilities including Git version control and build tools required by Homebrew. While not strictly required for Python development, these tools are prerequisites for most development workflows.

Open Terminal and run:

xcode-select --install
  • Click “Install” when the dialog appears
  • Accept the license agreement
  • Wait for installation to complete (5-15 minutes)

Alternative: Full Xcode Installation

If you plan to develop iOS apps or need the full Xcode IDE:

  • Open App Store
  • Search for “Xcode”
  • Install Xcode (requires ~15GB disk space)
  • Launch Xcode and install additional components when prompted

Step 3: Install Homebrew Package Manager

Homebrew is the essential package manager for macOS, similar to apt-get for Ubuntu or yum for Red Hat Linux. It simplifies installing and managing development tools, applications, and libraries from the command line.

Installation Command

In your Terminal, run the official Homebrew installation script:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Enter your password when prompted
  • Press Enter to continue installation
  • Follow any additional setup instructions displayed

Understanding Homebrew Package Types

Homebrew offers two package types:

  • Formulas (brew): Command-line tools and libraries
  • Casks (brew –cask): GUI applications

Example Usage

# Install a GUI application
brew install --cask firefox

# Install a command-line tool
brew install git

Test your Homebrew installation by running one of the above commands. Search for packages at formulae.brew.sh.

Step 4: Install Visual Studio Code

Visual Studio Code is the world’s most popular code editor, offering excellent Python support with IntelliSense, debugging, Git integration, and extensive extension marketplace. Built on Electron, it runs consistently across all platforms.

brew install --cask visual-studio-code

Alternative: Direct Download

You can also download VS Code directly from code.visualstudio.com/download and install manually.

💡 Essential Extensions: After installing VS Code, add the Python extension by Microsoft for the best Python development experience with syntax highlighting, IntelliSense, and debugging support.

Step 5: Install Python 3

While macOS includes Python 2.7 by default, Python 2 reached end-of-life on January 1, 2020. Modern Python development requires Python 3, which offers improved performance, better Unicode support, and active security updates.

Install Python 3 via Homebrew

brew install python

This installs the latest Python 3 version along with pip3 (Python’s package installer).

Verify Installation

# Check Python version
python3 --version

# Check pip version
pip3 --version

⚠️ Important: Always use python3 and pip3 commands on macOS to ensure you’re using Python 3, not the system’s Python 2.7.

Step 6: Install Virtual Environments

Virtual environments create isolated Python environments for each project, preventing package conflicts and ensuring reproducible setups. This is essential for professional Python development, allowing different projects to use different package versions without interference.

Install virtualenv

pip3 install virtualenv --user

The --user flag installs virtualenv to your user directory, avoiding system-wide installation issues.

Basic Virtual Environment Usage

# Create a new virtual environment
virtualenv myproject

# Activate the environment (macOS/Linux)
source myproject/bin/activate

# Install packages (only affects this environment)
pip install requests flask

# Deactivate when done
deactivate

💡 Pro Tip: Create a dedicated folder for your Python projects and always activate the appropriate virtual environment before working on a project.

Step 7: Test Your Development Environment

Let’s verify everything is working correctly by creating and running a simple Python program in VS Code.

Create Your First Python Program

  • Launch Visual Studio Code
  • Create a new file: File → New File
  • Type the following code:
print('Hello World!')
print('Python development environment is ready!')
  • Save the file as hello.py
  • Open Terminal in VS Code: Terminal → New Terminal
  • Run your program:
python3 hello.py

You should see both messages printed in the terminal. Congratulations! Your Mac Python development environment is now fully configured and ready for professional development.

Quick Reference: All Commands

For easy reference, here are all the installation commands in sequence. Copy and paste these into Terminal one at a time:

# Install Xcode Command Line Tools
xcode-select --install

# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install VS Code
brew install --cask visual-studio-code

# Install Python 3
brew install python

# Install virtual environments
pip3 install virtualenv --user

Next Steps for Python Development

  • Install the Python extension in VS Code
  • Learn Git version control basics
  • Explore Python frameworks like Django or Flask
  • Set up project-specific virtual environments
  • Configure VS Code for Python debugging

Frequently Asked Questions

Find answers to common questions

Homebrew strongly recommended—easier updates, better PATH management, includes pip/certificates. Python.org installer issues: manual PATH setup, certificate installation required (run Install Certificates.command), harder to upgrade. Homebrew advantages: brew install python installs Python 3.11+ with pip, automatic certificates, brew upgrade python updates easily, integrates with system. Installation: install Homebrew (5 mins), then brew install python (2 mins). Python.org advantages: official, works offline, simpler for non-developers. Version check: brew installs at /opt/homebrew/bin/python3 (M1/M2) or /usr/local/bin/python3 (Intel), python.org at /Library/Frameworks/Python.framework. Multiple versions: use pyenv (brew install pyenv) to manage Python 3.9, 3.10, 3.11 side-by-side. Recommendation: Homebrew for developers, Python.org for one-off scripting. Migration: uninstall Python.org version, install via Homebrew (clean slate).

python command: removed from macOS Catalina+ (used to be Python 2.7), now shows "command not found" on fresh Macs. python3 command: symlink to latest Python 3 version installed (usually python3.11 or python3.12). python3.11 command: specific version (useful when multiple Python 3 versions installed). Best practice: use python3 for general work (future-proof), python3.11 for version-specific needs (CI/CD, reproducibility). Check which: which python3 shows path (/opt/homebrew/bin/python3 for Homebrew), python3 --version shows actual version (Python 3.11.5). Virtual environments: python3 -m venv creates venv, then ./venv/bin/python is isolated Python (version locked at creation). IDE configuration: VS Code auto-detects python3, set interpreter path to specific version if needed. Create python alias: add to ~/.zshrc: alias python=python3 (makes python command work). Avoid: installing Python 2 (end-of-life 2020, security risks).

Step 1: Install VS Code (brew install --cask visual-studio-code or download .dmg). Step 2: Install Python extension (Microsoft's Python extension, 50M+ downloads). Step 3: Select interpreter—Cmd+Shift+P → "Python: Select Interpreter" → choose /opt/homebrew/bin/python3. Step 4: Create workspace folder, open in VS Code, create venv: python3 -m venv venv. Step 5: VS Code auto-detects venv, prompts to activate (click Yes). Step 6: Install linting/formatting—pip install black flake8 mypy, enable in VS Code settings. Configuration: settings.json: {"python.linting.enabled": true, "python.formatting.provider": "black", "editor.formatOnSave": true}. Debugging: click Run/Debug, creates launch.json, F5 to debug. Extensions: Python, Pylance (IntelliSense), autoDocstring (docstrings), GitLens (Git). Time: 15-20 mins full setup. Shortcuts: Cmd+Shift+P (command palette), Shift+Enter (run line/selection in terminal), F5 (debug).

pip: Python 2 package manager (mostly removed from modern macOS). pip3: Python 3 package manager (standard). Best practice: use python3 -m pip instead of pip3—guarantees using Python 3's pip, avoids PATH confusion. Why python3 -m pip better: explicitly calls Python 3's pip module, works in virtual environments, avoids multiple pip versions. Check version: pip3 --version shows Python 3.x (if Python 3.11, shows pip for Python 3.11). Multiple Python 3 versions: pip3 uses default python3, python3.11 -m pip uses specific version. Virtual environment: activate venv, then use pip (not pip3)—automatically tied to venv's Python version. Installation: python3 -m pip install requests (clear), pip3 install requests (shorter but ambiguous). Upgrade pip: python3 -m pip install --upgrade pip. Homebrew Python: creates both pip and pip3 symlinks (both point to Python 3). Recommendation: always use python3 -m pip for clarity and safety.

Virtual environments (venv) essential—isolates dependencies per project. Setup per project: cd my_project, python3 -m venv venv (creates isolated environment), source venv/bin/activate (activates), pip install -r requirements.txt (installs project deps). Benefits: project A uses Django 3.2, project B uses Django 4.1 (no conflict), delete venv folder to reset (clean slate), portable (share requirements.txt with team). Activation: source venv/bin/activate (terminal shows (venv) prefix), which python shows project's venv path. Deactivate: deactivate command (returns to system Python). Version management: pyenv manages Python versions (3.9, 3.10, 3.11), venv manages packages within version. Workflow: pyenv install 3.11, pyenv local 3.11 (sets project Python version), python -m venv venv (creates 3.11 venv). Tools: pipenv (combines pip + venv), poetry (modern dependency management). Time cost: 2-5 mins per new project. IDE: VS Code auto-detects venv, PyCharm has built-in venv UI.

Automate Your IT Operations

Leverage automation to improve efficiency, reduce errors, and free up your team for strategic work.