This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
install-python
50 lines (50 loc) · 1.79 KB
/
install-python
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
# !/bin/echo This script needs to be sourced, not executed!
# This script requires pyenv to be setup.
# The PYTHON environment variable must be set to the desired Python version, or the latest stable will be used
set -e
if [ $TRAVIS_OS_NAME = "windows" ]
then
PYENV="$HOME/.pyenv"
if [ "$(ls -A $PYENV)" ]
then
echo "pyenv-win seems to be already installed (cached?)"
else
echo "Installing pyenv-win"
travis_retry git clone --depth=1 https://github.com/pyenv-win/pyenv-win.git $PYENV
fi
export PYENV_ROOT="$HOME/.pyenv/pyenv-win"
ls -ahl $PYENV_ROOT
ls -ahl $PYENV_ROOT/bin
PYENV_ADDITIONAL_OPTIONS="-q"
else
export PYENV_ROOT="$HOME/.pyenv"
if [ "$(ls -A $PYENV_ROOT)" ]
then
echo "pyenv seems to be already installed (cached?)"
else
echo "Installing pyenv"
travis_retry git clone --depth=1 https://github.com/pyenv/pyenv.git $PYENV_ROOT
fi
PYENV_ADDITIONAL_OPTIONS="--skip-existing"
fi
export PATH="$PYENV_ROOT/bin:$PYENV_ROOT/shims:$PATH"
# eval "$(pyenv init -)"
echo Testing pyenv
pyenv commands || exit 1
echo "Done with pyenv. Now installing Python."
LATEST_PYTHON_STABLE=$(pyenv install -l | awk '{$1=$1};1' | sort -r | grep -E '^([0-9]*\.)*[0-9]*$' -m 1)
echo "The latest version available on pyenv is $LATEST_PYTHON_STABLE"
PYTHON="${PYTHON:-$LATEST_PYTHON_STABLE}"
echo "Python version selected: $PYTHON. Installing..."
travis_retry pyenv install $PYENV_ADDITIONAL_OPTIONS $PYTHON
echo "...done. Setting global to ${PYTHON}..."
pyenv global $PYTHON
pyenv rehash
echo "...done. Checking version."
echo "python -V: $(python -V)"
python -V | grep "$PYTHON" || (echo mismatched python version && false)
echo "pip -V"
pip -V || false
echo "Python is set to $(which python)"
echo "pip is set to $(which pip)"
set +e