Python: Installation Guide for macOS
0:00
0:00
Installing Python 3.10+ on macOS
Shell Script: Clean Python 3.10+ Install on macOS
NOTE: This is for 3.10+, but the version can be for Python 3.11 or 3.12
Save the following as install_python_mac.sh and run it with:
chmod +x install_python_mac.sh
./install_python_mac.sh
install_python_mac.sh
#!/bin/bash
set -e # Exit if any command fails
echo "🔍 Checking for Homebrew..."
if ! command -v brew &> /dev/null; then
echo "📦 Homebrew not found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
echo "✅ Homebrew is already installed."
fi
echo "🔄 Updating Homebrew..."
brew update
echo "🐍 Installing Python 3.10 via Homebrew..."
brew install python@3.10
# Don't link globally unless explicitly needed
echo "📍 Python installed at:"
brew --prefix python@3.10
PYTHON_BIN="$(brew --prefix python@3.10)/bin/python3.10"
echo "🔧 Installing pip and virtualenv..."
"$PYTHON_BIN" -m ensurepip --upgrade
"$PYTHON_BIN" -m pip install --upgrade pip virtualenv
echo "✅ Verifying installation..."
"$PYTHON_BIN" --version
"$PYTHON_BIN" -m pip --version
echo "🧪 Creating test virtual environment..."
"$PYTHON_BIN" -m venv testenv
source testenv/bin/activate
echo "🟢 Virtual environment activated. Python version:"
python --version
deactivate
rm -rf testenv
echo "🎉 Clean Python 3.10+ installation complete!"
echo "👉 Use '$PYTHON_BIN' directly or create virtual environments for safe development."
🔐 What This Script Does Not Do (on purpose)
-
❌ It does NOT override
python3orpip3globally- Keeps your macOS system Python intact
- Safer for beginners and long-term usage
-
❌ It does NOT force-link Homebrew Python
-
You can do that manually with:
brew link --overwrite python@3.10 --force
-