-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_pyenv.sh
executable file
·87 lines (62 loc) · 2.54 KB
/
install_pyenv.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
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
echo -e "\n\nThis script helps install pyenv on your computer (Debian/Alpine/MacOS)... \n\n"
echo -e "It may take a while & you may have to answer some questions. Prepare yourself for boredom... \n\n"
function add_pyenv_path() {
# add pyenv scripting to user profile (this is portable across zsh bash etc. - hopefully)
echo -e "\n\n\n" >> ~/.profile
cat << 'eof' >> ~/.profile
# ===== BEGIN PYENV STUFF =====
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"
# ===== END PYENV STUFF =====
eof
source ~/.profile
}
# load all the ingredients to install pyenv
if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Debian Linux
echo -e "Installing OS dependencies... \n\n"
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
elif [[ "$OSTYPE" == "darwin"* ]]; then # MacOS
echo -e "Installing brew dependencies... \n\n"
brew update
brew install openssl readline sqlite3 xz zlib
elif [[ "$OSTYPE" == "linux-musl"* ]]; then # Alpine Linux
echo -e "Installing OS dependencies... \n\n"
apk add libffi-dev ncurses-dev openssl-dev readline-dev \
tk-dev xz-dev zlib-dev
else
echo -e "Sorry, the script can't find your OS type... \n"
echo -e "Please use the directions from https://realpython.com/intro-to-pyenv/ to install pyenv to your computer. \n\n"
exit 1
fi
if [[ ! -d ~/.pyenv ]]; then
curl https://pyenv.run | bash
else
echo -e "\n\nPyenv seems to have already been installed before. Please check pyenv documentation for installation details.\n"
echo -e "If you wish to install again, please delete '~/.pyenv' and any pyenv lines from your shell profile.\n\n"
exit 1
fi
if [[ ! -f ~/.profile ]]; then
if touch ~/.profile ; then
add_pyenv_path
echo -e "User .profile added to shell configuration.\n\n"
else
# try to create the .profile or give user hints
echo -e "Please create .profile in your user home directory, then append the following lines to it... \n\n"
cat << 'eof'
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"
eof
exit 1
fi
else
add_pyenv_path
fi
# restart the session to reload user environment - WARNING: nothing will run after this line!
exec $SHELL -l