Python Installation, 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 python3 or pip3 globally

    • 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
      

Last updated on August 15, 2025

๐Ÿ” Explore More Topics

Discover related content that might interest you

TwoAnswers Logo

Providing innovative solutions and exceptional experiences. Building the future.

ยฉ 2025 TwoAnswers.com. All rights reserved.

Made with by the TwoAnswers.com team