<jupyter_start><jupyter_text>Jupyter Notebook for Checking Python Package Requirements<jupyter_code>from distutils.version import LooseVersion as Version


def get_packages(pkgs):
    versions = []
    for p in packages:
        try:
            imported = __import__(p)
            try:
                versions.append(imported.__version__)
            except AttributeError:
                try:
                    versions.append(imported.version)
                except AttributeError:
                    try:
                        versions.append(imported.version_info)
                    except AttributeError:
                        versions.append('0.0')
        except ImportError:
            print('[FAIL]: %s is not installed' % p)
    return versions
                    
packages = ['numpy', 'scipy', 'matplotlib', 'sklearn', 'pandas']
suggested_v = ['1.10', '0.17', '1.5.1', '0.17.1', '0.17.1']
versions = get_packages(packages)

for p, v, s in zip(packages, versions, suggested_v):
    if Version(v) < Version(s):
        print('[FAIL] %s %s, please upgrade to >= %s' % (p, v, s))
    else:
        print('[OK] %s %s' % (p, v))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12213740458015267, 'fraction_numerical': 0.016115351993214587, 'mean_word_length': 1.9949238578680204, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '308769', 'license': 'MIT', 'n_tokens_mistral': 366, 'n_tokens_neox': 350, 'n_words': 86, 'path': 'code/check_environment.ipynb', 'repo_name': 'purushothamgowthu/python-machine-learning-book', 'size': '1179'}