quyeticb commited on
Commit
6806dbe
·
verified ·
1 Parent(s): b446d96

Create install_python.sh

Browse files
Files changed (1) hide show
  1. install_python.sh +42 -0
install_python.sh ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Script to automatically install Python 3.11 on macOS using Homebrew
4
+
5
+ # Exit on any error
6
+ set -e
7
+
8
+ # Check if Homebrew is installed
9
+ if ! command -v brew &> /dev/null; then
10
+ echo "Homebrew not found. Installing Homebrew..."
11
+ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
12
+
13
+ # Add Homebrew to PATH for the current session
14
+ eval "$(/opt/homebrew/bin/brew shellenv)"
15
+ else
16
+ echo "Homebrew already installed."
17
+ fi
18
+
19
+ # Update Homebrew
20
+ echo "Updating Homebrew..."
21
+ brew update
22
+
23
+ # Install Python 3.11
24
+ echo "Installing Python 3.11..."
25
+ brew install python@3.11
26
+
27
+ # Verify installation
28
+ echo "Verifying Python 3.11 installation..."
29
+ python3.11 --version
30
+
31
+ # Add Python 3.11 to PATH if not already present
32
+ PYTHON_PATH="/opt/homebrew/opt/python@3.11/bin"
33
+ if [[ ":$PATH:" != *":$PYTHON_PATH:"* ]]; then
34
+ echo "Adding Python 3.11 to PATH..."
35
+ echo "export PATH=\"$PYTHON_PATH:\$PATH\"" >> ~/.zshrc
36
+ source ~/.zshrc
37
+ fi
38
+
39
+ ln -sf /opt/homebrew/opt/python@3.11/bin/python3.11 /usr/local/bin/python
40
+ ln -sf /opt/homebrew/opt/python@3.11/bin/pip3.11 /usr/local/bin/pip
41
+
42
+ echo "Python 3.11 has been successfully installed!"