Skip to content

Instantly share code, notes, and snippets.

@planetceres
Created March 6, 2019 21:46
Show Gist options
  • Save planetceres/62e92a9183903f6004fabfce18443d7e to your computer and use it in GitHub Desktop.
Save planetceres/62e92a9183903f6004fabfce18443d7e to your computer and use it in GitHub Desktop.
Set Python System Default to 2 or 3
!#/bin/bash
set_python () {
DEFAULT_PYTHON_PATH=$(readlink /usr/bin/python)
DEFAULT_PYTHON=${DEFAULT_PYTHON_PATH##*-}
if [[ $1 = 2* ]]; then
PYTHON_SET_VERSION=2
elif [[ $1 = 3* ]]; then
PYTHON_SET_VERSION=3
else
# Get user input for python version
read -p "Enter python version [default=$DEFAULT_PYTHON]: " PYTHON_SET
echo ""
if [[ $PYTHON_SET = 2* ]]; then
PYTHON_SET_VERSION=2
elif [[ $PYTHON_SET = 3* ]]; then
PYTHON_SET_VERSION=3
else
echo "Invalid python version"
return 1
fi
fi
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python$PYTHON_SET_VERSION /usr/bin/python
echo "Setting Default Python to:"
echo $(python -V)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment