Skip to content

Instantly share code, notes, and snippets.

@slopp
Created June 21, 2021 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slopp/1c01ac7b0ab432d1b66ef2966bbe51ba to your computer and use it in GitHub Desktop.
Save slopp/1c01ac7b0ab432d1b66ef2966bbe51ba to your computer and use it in GitHub Desktop.
Python Install

Install Python

This script is designed to make it easy to install multiple versions of Python onto a Linux system. The resulting versions are stored side-by-side in /opt/Python/

Instructions

  1. Copy the bash script to install-python,sh
  2. Make the script executable: sudo chmod +x install-python.sh
  3. Run the script for each desired python version, e.g. sudo ./install-python.sh 3.8.3

Details

This script uses miniconda to install pre-compiled Python binares. Once installed, conda is no longer required. See detailed documenetation at https://docs.rstudio.com/resources/install-python

#!/usr/bin/env bash
# Copyright (C) 2020 by RStudio, PBC.
set -o errexit
set -o nounset
set -o pipefail
main() {
python_version="${1:-}"
if [[ ! "${python_version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
cat << EOF
Usage: $(basename "$0") <python-version>
EOF
exit 1
fi
if [[ ! -d /opt/Python/miniconda ]]; then
echo "Downloading miniconda..."
curl -fsSL -o /opt/rstudio-connect/scripts/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-4.7.12.1-Linux-x86_64.sh
chmod 755 /opt/rstudio-connect/scripts/miniconda.sh
echo "Installing miniconda..."
/opt/rstudio-connect/scripts/miniconda.sh -b -p /opt/Python/miniconda
fi
if [[ ! -f /opt/Python/"${python_version}"/bin/python ]]; then
echo "Installing Python ${python_version}..."
/opt/Python/miniconda/bin/conda create --quiet --yes \
--prefix /opt/Python/"${python_version}" \
--channel conda-forge \
python="${python_version}" virtualenv notebook nbconvert bjoern
if [[ "${python_version}" =~ ^3 ]]; then
/opt/Python/"${python_version}"/bin/pip install --upgrade \
pip setuptools wheel
fi
fi
echo "Finished installing Python ${python_version}"
}
main "${@}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment