-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_python.sh
More file actions
executable file
·238 lines (181 loc) · 9.69 KB
/
Copy pathinstall_python.sh
File metadata and controls
executable file
·238 lines (181 loc) · 9.69 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/bin/bash
# Run: bash <(curl -fsSL "https://env.arturonavax.dev/install_python.sh")
# Flag to install update available: -i
set -o errexit
trap exit-error-message ERR SIGINT
# Reset Text Color
fgcolor_reset='\033[0m'
fgcolor_cyan='\033[0;36m'
# Bold Text Colors
fgcolor_white_bold='\033[1;37m'
fgcolor_yellow_bold='\033[1;33m'
fgcolor_red='\033[0;31m'
fgcolor_red_bold='\033[1;31m'
fgcolor_green='\033[0;32m'
fgcolor_green_bold='\033[1;32m'
fgcolor_cyan_bold='\033[1;36m'
function exit-error-message() {
echo
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_red_bold}The installation had an error and was interrupted, the installation was not completed.${fgcolor_reset}"
exit 1
}
if [[ "$(command -v curl)" == "" ]]; then
echo "${fgcolor_white_bold}[Python Installer]: ${fgcolor_red_bold}The curl command is needed to execute this script.${fgcolor_reset}"
exit 1
fi
while getopts ':i' flag; do
case "$flag" in
i)
install_flag=1
;;
*)
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_red_bold}Unknown flag${fgcolor_reset}, only ${fgcolor_green_bold}'-i'${fgcolor_reset} is accepted to install."
exit 1
;;
esac
done
if [[ "$(uname -s)" == "Darwin" ]]; then
if [[ ! -e "/Library/Developer/CommandLineTools/usr/bin/git" ]]; then
# install CommandLineTools (this contains GIT)
curl -fsSL "https://env.arturonavax.dev/macos_install_clt.sh" | bash || exit 1
fi
# Homebrew
if [[ "$(command -v brew)" == "" ]]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brewbin="/usr/local/bin/brew"
[[ ! -f "$brewbin" ]] && brewbin="/opt/homebrew/bin/brew" # For Apple Silicon
[[ -f "$brewbin" ]] && eval "$("$brewbin" shellenv)"
if [[ "$(command -v brew)" == "" ]]; then
echo "${fgcolor_white_bold}[Python Installer]: ${fgcolor_red}Homebrew installation error occurred." && exit 1
fi
fi
echo -e "${fgcolor_white_bold}[Python Installer]: 🔎 Finding latest version of Python ${fgcolor_yellow_bold}🐍${fgcolor_white_bold}...${fgcolor_reset}"
export PYENV_ROOT="$HOME/.pyenv"
if [[ ":$PATH:" != *":$PYENV_ROOT/bin:"* ]]; then
export PATH="$PYENV_ROOT/bin:$PATH"
fi
if [[ ! -d ~/.pyenv/ ]]; then
echo -e "${fgcolor_white_bold}[Python Installer]: - Installing pyenv (python version manager)...${fgcolor_reset}"
if [[ "$(uname -s)" == "Linux" ]]; then
# download pyenv
curl -fsSL https://pyenv.run | bash
elif [[ "$(uname -s)" == "Darwin" ]]; then
brew reinstall pyenv
fi
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_green_bold}✔️ pyenv installation completed...${fgcolor_reset}"
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_reset}# Add pyenv to PATH: ${fgcolor_cyan}export PATH=\"\$HOME/.pyenv/bin:\$PATH\" && eval \"\$(pyenv init -)\"${fgcolor_reset}"
fi
eval "$(pyenv init -)"
if [[ "$(uname -s)" == "Linux" ]]; then
pyenv update &>/dev/null
fi
latest_version="$(pyenv install -l | command grep -E -o '^[[:space:]]*[0-9]+(\.[0-9]+){1,2}$' |
sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | sort --version-sort | tail -n 1)"
# sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | awk -F. '$1 < 3 || ($1 == 3 && $2 <= 11)' | sort --version-sort | tail -n 1)"
if [[ "$(command -v python3)" == "" ]]; then
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_red}❌ Python is not installed on this system..${fgcolor_reset}"
else
current_version="$(python3 --version | awk '{print $2}')"
if ! command -v python3 | grep -q ".pyenv"; then
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_yellow_bold}⚠️ The installed Python was not installed with pyenv.${fgcolor_reset}"
fi
if [[ "$latest_version" != "$current_version" ]]; then
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_yellow_bold}⚠️ The version of Python installed is not the latest one.${fgcolor_reset}"
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_yellow_bold}ℹ️ The latest available version of Python is: $latest_version${fgcolor_reset}"
else
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_green}✔️ You have the latest version of Python: $latest_version${fgcolor_reset}"
fi
fi
if [[ "$install_flag" == 1 ]]; then
echo
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_cyan_bold}⚡ Running installation...${fgcolor_reset}"
echo -e "${fgcolor_white_bold}[Python Installer]: - Installing dependencies...${fgcolor_reset}"
# dependencies
if [[ "$(uname -s)" == "Linux" ]]; then
source /etc/os-release
if [[ "$ID_LIKE" == *"rhel"* || "$ID_LIKE" == *"centos"* ]]; then
sudo dnf update -y
sudo dnf install -y epel-release
fi
if [[ "$ID_LIKE" == *"debian"* || "$ID_LIKE" == *"ubuntu"* ]]; then
sudo apt update -y
sudo apt install -y build-essential gcc llvm make git wget curl findutils libssl-dev zlib1g-dev \
libbz2-dev libffi-dev liblzma-dev libxml2 libxml2-dev libxslt1-dev \
libreadline-dev libsqlite3-dev libncurses5-dev libncursesw5-dev ncurses-term \
libpq-dev xz-utils tk tk-dev python3-dev python3-venv python3-wheel python3-setuptools python3-tabulate python3-tk python3-openssl
elif [[ "$ID_LIKE" == *"rhel"* || "$ID_LIKE" == *"centos"* || "$ID_LIKE" == *"fedora"* || "$ID" == *"fedora"* ]]; then
sudo dnf update -y
sudo dnf group install -y "Development Tools"
sudo dnf install -y gcc make git wget curl libffi libffi-devel qt5-qtbase-devel bzip2 bzip2-devel findutils \
ncurses ncurses-devel ncurses-term sqlite sqlite-devel readline readline-devel zlib zlib-devel openssl openssl-devel \
libxml2 libxml2-devel libpq-devel xz xz-devel tk tk-devel python3-devel python3-setuptools python3-tabulate
if [[ "$ID" == *"fedora"* ]]; then
sudo dnf install -y python3-wheel
fi
else
echo "${fgcolor_white_bold}[Python Installer]: ${fgcolor_red_bold}❌ The operating system is not compatible with this installation."
exit 1
fi
elif [[ "$(uname -s)" == "Darwin" ]]; then
brew install curl wget git make gcc ncurses findutils sqlite openssl@3 readline zlib xz tcl-tk python@3.12 python-tk@3.12 python-setuptools python-tabulate
else
echo "${fgcolor_white_bold}[Python Installer]: ${fgcolor_red_bold}❌ The operating system is not compatible with this installation."
exit 1
fi
echo
# Install python if the current python is not from pyenv
echo -e "${fgcolor_white_bold}[Python Installer]: - Installing Python $latest_version...${fgcolor_reset}"
if ! command -v python3 | grep -q ".pyenv" || [[ "$latest_version" != "$current_version" ]]; then
# install python
if [[ "$(uname -s)" == "Linux" ]]; then
# env PYTHON_CONFIGURE_OPTS="--enable-shared" \
pyenv install -s "$latest_version"
elif [[ "$(uname -s)" == "Darwin" ]]; then
# env \
# PATH="$(brew --prefix tcl-tk)/bin:$PATH" \
# LDFLAGS="-L$(brew --prefix tcl-tk)/lib" \
# CPPFLAGS="-I$(brew --prefix tcl-tk)/include" \
# PKG_CONFIG_PATH="$(brew --prefix tcl-tk)/lib/pkgconfig" \
# CFLAGS="-I$(brew --prefix tcl-tk)/include" \
# PYTHON_CONFIGURE_OPTS="--enable-framework --with-tcltk-includes='-I$(brew --prefix tcl-tk)/include' --with-tcltk-libs='-L$(brew --prefix tcl-tk)/lib -ltcl8.6 -ltk8.6' " \
# env \
# LDFLAGS="-L$(brew --prefix openssl@3)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix sqlite)/lib -L$(brew --prefix xz)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix tcl-tk)/lib" \
# CPPFLAGS="-I$(brew --prefix openssl@3)/include -I$(brew --prefix readline)/include -I$(brew --prefix sqlite)/include -I$(brew --prefix xz)/include -I$(brew --prefix zlib)/include -I$(brew --prefix tcl-tk)/include" \
# PKG_CONFIG_PATH="$(brew --prefix openssl@3)/lib/pkgconfig:$(brew --prefix readline)/lib/pkgconfig:$(brew --prefix sqlite)/lib/pkgconfig:$(brew --prefix xz)/lib/pkgconfig:$(brew --prefix zlib)/lib/pkgconfig:$(brew --prefix tcl-tk)/lib/pkgconfig" \
pyenv install -s "$latest_version"
else
echo "${fgcolor_white_bold}[Python Installer]: ${fgcolor_red_bold}❌ The operating system is not compatible with this installation."
exit 1
fi
pyenv global "$latest_version"
eval "$(pyenv init -)"
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade tk
python3 -m pip install --upgrade setuptools
python3 -m pip install --upgrade wheel
python3 -m pip install --upgrade numpy
python3 -m pip install --upgrade pandas
python3 -m pip install --upgrade packaging
python3 -m pip install --upgrade requests
python3 -m pip install --upgrade opt_einsum
python3 -m pip install --upgrade keras_preprocessing --no-deps
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_green_bold}✔️ Python $latest_version installation completed...${fgcolor_reset}"
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_reset}# Add pyenv to PATH: ${fgcolor_cyan}export PATH=\"\$HOME/.pyenv/bin:\$PATH\" && eval \"\$(pyenv init -)\"${fgcolor_reset}"
echo
else
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_green_bold}✔️ Python $latest_version is already installed...${fgcolor_reset}"
echo
fi
echo -e "${fgcolor_white_bold}[Python Installer]: - Installing pipx (python binary installer)...${fgcolor_reset}"
if ! python3 -m pipx --version &>/dev/null && command -v python3 | grep -q ".pyenv"; then
# install pipx
python3 -m pip install --upgrade pip
python3 -m pip install --force --upgrade --user pipx
python3 -m pipx ensurepath
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_green_bold}✔️ pipx installation completed (add ~/.local/bin to PATH)...${fgcolor_reset}"
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_reset}# Add ~/.local/bin to PATH: ${fgcolor_cyan}export PATH=\"\$HOME/.local/bin:\$PATH\"${fgcolor_reset}"
else
echo -e "${fgcolor_white_bold}[Python Installer]: ${fgcolor_green_bold}✔️ pip is already installed...${fgcolor_reset}"
fi
fi