| 1 | #!/bin/bash |
| 2 | set -e |
| 3 | |
| 4 | echo "====================PYTHON START====================" |
| 5 | |
| 6 | echo "====================PYTHON 3.13====================" |
| 7 | |
| 8 | apt clean && apt-get update && apt-get -y upgrade |
| 9 | |
| 10 | # install python 3.13 globally |
| 11 | apt-get install -y --no-install-recommends \ |
| 12 | python3.13 python3.13-venv |
| 13 | #python3.13-dev |
| 14 | |
| 15 | |
| 16 | echo "====================PYTHON 3.13 VENV====================" |
| 17 | |
| 18 | # create and activate default venv |
| 19 | python3.13 -m venv /opt/venv |
| 20 | source /opt/venv/bin/activate |
| 21 | |
| 22 | # upgrade pip and install static packages |
| 23 | pip install --no-cache-dir --upgrade pip pipx ipython requests |
| 24 | |
| 25 | echo "====================PYTHON PYVENV====================" |
| 26 | |
| 27 | # Install pyenv build dependencies. |
| 28 | apt-get install -y --no-install-recommends \ |
| 29 | make build-essential libssl-dev zlib1g-dev libbz2-dev \ |
| 30 | libreadline-dev libsqlite3-dev wget curl llvm \ |
| 31 | libncursesw5-dev xz-utils tk-dev libxml2-dev \ |
| 32 | libxmlsec1-dev libffi-dev liblzma-dev |
| 33 | |
| 34 | # Install pyenv globally |
| 35 | git clone https://github.com/pyenv/pyenv.git /opt/pyenv |
| 36 | |
| 37 | # Setup environment variables for pyenv to be available system-wide |
| 38 | cat > /etc/profile.d/pyenv.sh <<'EOF' |
| 39 | export PYENV_ROOT="/opt/pyenv" |
| 40 | export PATH="$PYENV_ROOT/bin:$PATH" |
| 41 | eval "$(pyenv init --path)" |
| 42 | EOF |
| 43 | |
| 44 | # fix permissions |
| 45 | chmod +x /etc/profile.d/pyenv.sh |
| 46 | |
| 47 | # Source pyenv environment to make it available in this script |
| 48 | source /etc/profile.d/pyenv.sh |
| 49 | |
| 50 | # Install Python 3.12.4 |
| 51 | echo "====================PYENV 3.12 VENV====================" |
| 52 | pyenv install 3.12.4 |
| 53 | |
| 54 | /opt/pyenv/versions/3.12.4/bin/python -m venv /opt/venv-a0 |
| 55 | source /opt/venv-a0/bin/activate |
| 56 | |
| 57 | # upgrade pip and install static packages |
| 58 | pip install --no-cache-dir --upgrade pip pipx |
| 59 | |
| 60 | # Install some packages in specific variants |
| 61 | pip install --no-cache-dir \ |
| 62 | torch==2.4.0 \ |
| 63 | torchvision==0.19.0 \ |
| 64 | --index-url https://download.pytorch.org/whl/cpu |
| 65 | |
| 66 | echo "====================PYTHON UV ====================" |
| 67 | |
| 68 | curl -Ls https://astral.sh/uv/install.sh | UV_INSTALL_DIR=/usr/local/bin sh |
| 69 | |
| 70 | # clean up pip cache |
| 71 | pip cache purge |
| 72 | |
| 73 | echo "====================PYTHON END====================" |