Python SDK installer does not support dual python versions


#1

I tried to install the Python SDK on Ubuntu 18 but it failed because it was running python 2 commands with python, which didn’t exist because I have Py2 and 3 installed. On many systems Python2 is run with python2 and Python 3 is python3.

I fixed this script to use python2 -m pip instead of just pip.

I’ve fixed the installer, not sure what to do with it now.

#!/bin/bash

# The original install script provided by Hologram.io (https://github.com/hologram-io/hologram-python) does
# not work on systems with both Python 2 and 3 installed (where the command is python2 or python3).
# I fixed this script to use 'python2 -m pip' instead of just 'pip'.


# Author: Hologram <support@hologram.io>
#
# Copyright 2016 - Hologram (Konekt, Inc.)
#
# LICENSE: Distributed under the terms of the MIT License
#
# install.sh - This file helps install this Python SDK and all required dependencies
#              on a machine.

set -euo pipefail

# This script will install the Hologram SDK and the necessary software dependencies
# for it to work.

required_programs=('python' 'pip' 'ps' 'kill' 'libpython2.7-dev')
OS=''

# Check OS.
if [ "$(uname)" == "Darwin" ]; then

    echo 'Darwin system detected'
    OS='DARWIN'

elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then

    echo 'Linux system detected'
    OS='LINUX'
    required_programs+=('ip' 'pppd')

elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then

    echo 'Windows 32-bit system detected'
    OS='WINDOWS'

elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then

    echo 'Windows 64-bit system detected'
    OS='WINDOWS'
fi

# Error out on unsupported OS.
if [ "$OS" == 'DARWIN' ] || [ "$OS" == 'WINDOWS' ]; then
    echo "$OS is not supported right now"
    exit 1
fi

function pause() {
    read -p "$*"
}

function install_software() {
    if [ "$OS" == 'LINUX' ]; then
        sudo apt-get -y install "$*"
    elif [ "$OS" == 'DARWIN' ]; then
        brew install "$*"
        echo 'TODO: macOS should go here'
    elif [ "$OS" == 'WINDOWS' ]; then
        echo 'TODO: windows should go here'
    fi
}

# EFFECTS: Returns true if the specified program is installed, false otherwise.
function check_if_installed() {
    if command -v "$*" >/dev/null 2>&1; then
        return 0
    else
        return 1
    fi
}

function update_repository() {
    if [ "$OS" == 'LINUX' ]; then
        sudo apt-get update
    elif [ "$OS" == 'DARWIN' ]; then
        brew update
        echo 'TODO: macOS should go here'
    elif [ "$OS" == 'WINDOWS' ]; then
        echo 'TODO: windows should go here'
    fi
}

# EFFECTS: Verifies that all required software is installed.
function verify_installation() {
    echo 'Verifying that all dependencies are installed correctly...'
    # Verify pip packages
    INSTALLED_PIP_PACKAGES="$(python2 -m pip list)"

    if ! [[ "$INSTALLED_PIP_PACKAGES" == *"python-sdk-auth"* ]]; then
        echo 'Cannot find python-sdk-auth. Please rerun the install script.'
        exit 1
    fi

    if ! [[ "$INSTALLED_PIP_PACKAGES" == *"hologram-python"* ]]; then
        echo 'Cannot find hologram-python. Please rerun the install script.'
        exit 1
    fi

    echo 'You are now ready to use the Hologram Python SDK!'
}

update_repository

# Iterate over all programs to see if they are installed
# Installs them if necessary
for program in ${required_programs[*]}
do
    if [ "$program" == 'pppd' ]; then
        if ! check_if_installed "$program"; then
            pause "Installing $program. Press [Enter] key to continue...";
            install_software 'ppp'
        fi
    elif [ "$program" == 'pip' ]; then
        if ! check_if_installed "$program"; then
            pause "Installing $program. Press [Enter] key to continue...";
            install_software 'python-pip'
        fi
    elif check_if_installed "$program"; then
        echo "$program is already installed."
    else
        pause "Installing $program. Press [Enter] key to continue...";
        install_software "$program"
    fi
done

# Install SDK itself.
sudo python2 -m pip install hologram-python

verify_installation

#2

You probably need to alias python to point to python2 on your system or fork the Hologram SDK (which is open source) and manually change all the pythons to python2s. I would suggest the former.

It looks like PEP 394 recommends systems still use python to point to python2 and Ubuntu 18 should follow this convention.