-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpython-install.sh
executable file
·71 lines (55 loc) · 1.56 KB
/
python-install.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
#!/usr/bin/env bash
#
# Copyright (C) 2020-2024 Joelle Maslak
# All Rights Reserved - See License
#
PYTHON39=3.9.19
PYTHON310=3.10.14
PYTHON311=3.11.9
PYTHON312=3.12.4
PREFERRED="$PYTHON311"
doit() {
# Defensive umask
if [ "$(umask)" == '0000' ] ; then
umask 0002
fi
CWD=$(pwd)
# Install pyenv
if [ ! -d "$HOME/.pyenv" ] ; then
cd "$HOME" || echo >/dev/null
git clone https://github.com/yyuu/pyenv.git .pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
else
if ! command -v pyenv >/dev/null ; then
# pyenv not in path.
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
fi
cd "$HOME/.pyenv/" && git pull && cd - || echo >/dev/null
fi
# Install pyenv-virtualenv
if [ ! -d "$HOME/.pyenv/plugins/pyenv-virtualenv" ] ; then
cd "$HOME/.pyenv/plugins" || echo >/dev/null
git clone https://github.com/yyuu/pyenv-virtualenv.git pyenv-virtualenv
fi
install $PYTHON39
install $PYTHON310
install $PYTHON311
install $PYTHON312
echo "Setting Python version to $PREFERRED"
pyenv global "$PREFERRED"
pyenv rehash
cd "$CWD" || echo >/dev/null
}
install() {
PYVER="$1"
PYVERREGEX=${PYVER//./\\.}
# Install python
if ! pyenv versions 2>/dev/null | grep -P " $PYVERREGEX(\s.*)?$" >/dev/null ; then
PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install "$PYVER"
fi
}
doit "$@"