-
Notifications
You must be signed in to change notification settings - Fork 9
/
setup_mac_python.sh
executable file
·74 lines (59 loc) · 2.05 KB
/
setup_mac_python.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
PYTHON_VERSION=3.9.1
function installPyenv() {
# If changes need to be made to user's config file, detect the correct one
[[ "$SHELL" == *"bash"* ]] && config_file=".bashrc" || config_file=".zshrc"
if [ $(brew list | grep -c pyenv) != 1 ]; then
echo "Installing Pyenv"
brew install pyenv
else
echo "Skipping Pyenv install. Ensuring latest version of pip."
python3 -m pip install --upgrade pip
fi
if [[ PYENV_ROOT ]]; then
echo "Skipping Pyenv Configuration"
else
echo "
# Configure pyenv
export PYENV_ROOT=\"$HOME/.pyenv\"
export PIPENV_DIR=\"$HOME/.local\"
export PATH=$HOME/.local/bin:$HOME/.pyenv/bin:$PATH
if command -v pyenv 1>/dev/null 2>&1; then
export PATH=$(pyenv root)/shims:$PATH
eval "$(pyenv init -)"\n
fi" >>$HOME/$config_file
source $HOME/$config_file
fi
}
function installPython() {
installPyenv
versionInstalled=$(pyenv versions | grep -c "$PYTHON_VERSION")
if [ $versionInstalled != 1 ]; then
echo "Installing Python version $PYTHON_VERSION"
pyenv install ${PYTHON_VERSION}:latest
else
echo "Skipping $PYTHON_VERSION install"
fi
INSTALLED_PYTHON_VERSION=$(pyenv versions | grep -o ${PYTHON_VERSION}'.*[0-9]' | tail -1)
pyenv global $INSTALLED_PYTHON_VERSION
if [ $(python3 -m pip list | grep -c pipenv) != 1 ]; then
echo "Install pipenv and autopep8"
python3 -m pip install pipenv autopep8
else
echo "Skipping pipenv and autopep8 install"
fi
if [[ $(which pipenv) == "pipenv not found" ]]; then
echo "Could not find pipenv. Exiting installation process..."
return 0
fi
}
function installBrew() {
if ! type brew &>/dev/null; then
echo -e "\n\n\n\nInstalling Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval $(/opt/homebrew/bin/brew shellenv)' >>$HOME/.zprofile
eval $(/opt/homebrew/bin/brew shellenv)
fi
}
installBrew
installPython