Upload python.sh
Browse files
python.sh
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
set -e
|
| 4 |
+
|
| 5 |
+
echo "--------------------------------------------------------------------"
|
| 6 |
+
echo "IMPORTANT WARNING!"
|
| 7 |
+
echo "This script will configure Python 3.12 as the default system version."
|
| 8 |
+
echo "This MAY BREAK system tools that depend on the original"
|
| 9 |
+
echo "Python 3 version. Use at your own risk!"
|
| 10 |
+
echo "The safest alternative is to use virtual environments."
|
| 11 |
+
echo "--------------------------------------------------------------------"
|
| 12 |
+
read -p "Are you sure you want to continue? (y/N): " confirmation
|
| 13 |
+
if [[ ! "$confirmation" =~ ^[Yy]$ ]]; then
|
| 14 |
+
echo "Aborting."
|
| 15 |
+
exit 1
|
| 16 |
+
fi
|
| 17 |
+
|
| 18 |
+
echo ">>> [1/6] Installing dependencies and deadsnakes repository..."
|
| 19 |
+
apt update
|
| 20 |
+
apt install -y software-properties-common curl ca-certificates
|
| 21 |
+
add-apt-repository -y ppa:deadsnakes/ppa
|
| 22 |
+
apt update
|
| 23 |
+
|
| 24 |
+
echo ">>> [2/6] Installing Python 3.12 and associated packages..."
|
| 25 |
+
apt install -y python3.12 python3.12-venv python3.12-dev
|
| 26 |
+
|
| 27 |
+
echo ">>> [3/6] Installing pip for Python 3.12..."
|
| 28 |
+
curl -sS https://bootstrap.pypa.io/get-pip.py -o get-pip.py
|
| 29 |
+
/usr/bin/python3.12 get-pip.py
|
| 30 |
+
rm get-pip.py
|
| 31 |
+
|
| 32 |
+
echo ">>> [4/6] Configuring Python 3.12 as default using update-alternatives..."
|
| 33 |
+
|
| 34 |
+
CURRENT_PYTHON3_CMD=$(command -v python3 || echo "")
|
| 35 |
+
CURRENT_PYTHON3_PATH=""
|
| 36 |
+
if [[ -n "$CURRENT_PYTHON3_CMD" && -x "$CURRENT_PYTHON3_CMD" ]]; then
|
| 37 |
+
CURRENT_PYTHON3_PATH=$(readlink -f $CURRENT_PYTHON3_CMD)
|
| 38 |
+
fi
|
| 39 |
+
|
| 40 |
+
echo "Registering /usr/bin/python3.12 with priority 100..."
|
| 41 |
+
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 100
|
| 42 |
+
|
| 43 |
+
if [[ -n "$CURRENT_PYTHON3_PATH" && "$CURRENT_PYTHON3_PATH" != "/usr/bin/python3.12" && -x "$CURRENT_PYTHON3_PATH" ]]; then
|
| 44 |
+
echo "Registering previous version found ($CURRENT_PYTHON3_PATH) with priority 50..."
|
| 45 |
+
update-alternatives --install /usr/bin/python3 python3 "$CURRENT_PYTHON3_PATH" 50
|
| 46 |
+
else
|
| 47 |
+
echo "Previous version not registered (or it was the same 3.12)."
|
| 48 |
+
fi
|
| 49 |
+
|
| 50 |
+
echo "Setting /usr/bin/python3.12 as the selection for python3..."
|
| 51 |
+
update-alternatives --set python3 /usr/bin/python3.12
|
| 52 |
+
|
| 53 |
+
echo ">>> [5/6] Cleaning apt cache..."
|
| 54 |
+
apt clean
|
| 55 |
+
|
| 56 |
+
echo ">>> [6/6] Final verification..."
|
| 57 |
+
echo "Default python3 version:"
|
| 58 |
+
python3 --version
|
| 59 |
+
|
| 60 |
+
echo "Pip version associated with default python3:"
|
| 61 |
+
python3 -m pip --version
|
| 62 |
+
|
| 63 |
+
echo "Default python3 executable path:"
|
| 64 |
+
command -v python3
|
| 65 |
+
ls -l $(command -v python3)
|
| 66 |
+
|
| 67 |
+
echo ""
|
| 68 |
+
echo "--------------------------------------------------------------------"
|
| 69 |
+
echo "Done! Python 3.12 should now be the default version."
|
| 70 |
+
echo "Remember the warning about potential system breakage."
|
| 71 |
+
echo "--------------------------------------------------------------------"
|
| 72 |
+
|
| 73 |
+
exit 0
|