File size: 1,180 Bytes
6806dbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash

# Script to automatically install Python 3.11 on macOS using Homebrew

# Exit on any error
set -e

# Check if Homebrew is installed
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)"
    
    # Add Homebrew to PATH for the current session
    eval "$(/opt/homebrew/bin/brew shellenv)"
else
    echo "Homebrew already installed."
fi

# Update Homebrew
echo "Updating Homebrew..."
brew update

# Install Python 3.11
echo "Installing Python 3.11..."
brew install python@3.11

# Verify installation
echo "Verifying Python 3.11 installation..."
python3.11 --version

# Add Python 3.11 to PATH if not already present
PYTHON_PATH="/opt/homebrew/opt/python@3.11/bin"
if [[ ":$PATH:" != *":$PYTHON_PATH:"* ]]; then
    echo "Adding Python 3.11 to PATH..."
    echo "export PATH=\"$PYTHON_PATH:\$PATH\"" >> ~/.zshrc
    source ~/.zshrc
fi

ln -sf /opt/homebrew/opt/python@3.11/bin/python3.11 /usr/local/bin/python
ln -sf /opt/homebrew/opt/python@3.11/bin/pip3.11 /usr/local/bin/pip

echo "Python 3.11 has been successfully installed!"