Python Installation, macOS
0:000: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
orpip3
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
-