<jupyter_start><jupyter_text>Notebook to Check a JupyterHub Software Environment <img src= "https://github.com/waterhackweek/waterhackweek.github.io/blob/master/assets/images/waterhackweek2020logo-words.JPG?raw=true"style="float:left;width:175px;padding:10px">   Github Source: [WHW2020_machinelearning tutorial on Github](https://github.com/waterhackweek/whw2020_machine_learning)Authors: [<NAME>](https://github.com/amueller), [<NAME>](https://github.com/ChristinaB) List of open source software requirements with specific versions for WHW2020 Landslide Machine Learning Tutorial<jupyter_code>requirements = {'numpy': "1.6.1", 'scipy': "1.0", 'matplotlib': "2.0",
                'IPython': "3.0", 'sklearn': "0.22.1", 'pandas': "0.18"}<jupyter_output><empty_output><jupyter_text>Software Imports and Functions<jupyter_code>from distutils.version import LooseVersion as Version
import sys


OK = '\x1b[42m[ OK ]\x1b[0m'
FAIL = "\x1b[41m[FAIL]\x1b[0m"

try:
    import importlib
except ImportError:
    print(FAIL, "Python version 3.5 is required,"
                " but %s is installed." % sys.version)

    
def import_version(pkg, min_ver, fail_msg=""):
    mod = None
    try:
        mod = importlib.import_module(pkg)
        ver = mod.__version__
        if Version(ver) < min_ver:
            print(FAIL, "%s version %s or higher required, but %s installed."
                  % (lib, min_ver, ver))
        else:
            print(OK, '%s version %s' % (pkg, ver))
    except ImportError:
        print(FAIL, '%s not installed. %s' % (pkg, fail_msg))
    return mod<jupyter_output><empty_output><jupyter_text>First Check with Python version<jupyter_code>print('Using python in', sys.prefix)
print(sys.version)
pyversion = Version(sys.version)
if pyversion < "3.5":
    print(FAIL, "Python version 3.5 is required,"
                " but %s is installed." % sys.version)
print()


# now the dependencies
for lib, required_version in list(requirements.items()):
    import_version(lib, required_version)<jupyter_output>Using python in /home/jovyan/data/conda-envs/covid19
3.8.2 | packaged by conda-forge | (default, Apr 24 2020, 08:20:52) 
[GCC 7.3.0]

[42m[ OK ][0m numpy version 1.18.4
[42m[ OK ][0m scipy version 1.4.1
[42m[ OK ][0m matplotlib version 3.3.3
[42m[ OK ][0m IPython version 7.17.0
[42m[ OK ][0m sklearn version 0.23.2
[42m[ OK ][0m pandas version 1.1.0<jupyter_text>Install missing software **Note: In this example, sklearn and matplotlib are missing in the CUAHSI JupyterHub COVID19 Kernel, and so installed below**<jupyter_code>import sys
!{sys.executable} -m pip install sklearn
!{sys.executable} -m pip install matplotlib<jupyter_output>Requirement already satisfied: sklearn in /home/jovyan/data/conda-envs/covid19/lib/python3.8/site-packages (0.0)
Requirement already satisfied: scikit-learn in /home/jovyan/data/conda-envs/covid19/lib/python3.8/site-packages (from sklearn) (0.23.2)
Requirement already satisfied: numpy>=1.13.3 in /home/jovyan/data/conda-envs/covid19/lib/python3.8/site-packages (from scikit-learn->sklearn) (1.18.4)
Requirement already satisfied: scipy>=0.19.1 in /home/jovyan/data/conda-envs/covid19/lib/python3.8/site-packages (from scikit-learn->sklearn) (1.4.1)
Requirement already satisfied: threadpoolctl>=2.0.0 in /home/jovyan/data/conda-envs/covid19/lib/python3.8/site-packages (from scikit-learn->sklearn) (2.1.0)
Requirement already satisfied: joblib>=0.11 in /home/jovyan/data/conda-envs/covid19/lib/python3.8/site-packages (from scikit-learn->sklearn) (0.17.0)
Requirement already satisfied: matplotlib in /home/jovyan/data/conda-envs/covid19/lib/python3.8/site-packages (3.3.3)
Requirement already satis[...]<jupyter_text>After installing missing libraries, run the version check for full list to ensure installation is OK.<jupyter_code>for lib, required_version in list(requirements.items()):
    import_version(lib, required_version)<jupyter_output>[42m[ OK ][0m numpy version 1.18.4
[42m[ OK ][0m scipy version 1.4.1
[42m[ OK ][0m matplotlib version 3.3.3
[42m[ OK ][0m IPython version 7.17.0
[42m[ OK ][0m sklearn version 0.23.2
[42m[ OK ][0m pandas version 1.1.0
{'fraction_non_alphanumeric': 0.14082811747713048, 'fraction_numerical': 0.05247953779489649, 'mean_word_length': 4.459921156373193, 'pattern_counts': {'":': 1, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '54451', 'license': 'CC0-1.0', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1505, 'n_words': 333, 'path': 'whw2020_check_jh_env.ipynb', 'repo_name': 'waterhackweek/water_hackweek_2020_machine_learning', 'size': '4177'}