|
| 1 | +# This script is adapted from Andreas Mueller: |
| 2 | +# https://github.com/amueller/scipy-2018-sklearn/blob/master/check_env.ipynb |
| 3 | +# and glemaitre: https://github.com/glemaitre/pyparis-2018-sklearn/blob/master/check_environment.py |
| 4 | + |
| 5 | +from __future__ import print_function |
| 6 | +from distutils.version import LooseVersion as Version |
| 7 | +import sys |
| 8 | + |
| 9 | + |
| 10 | +try: |
| 11 | + import curses |
| 12 | + curses.setupterm() |
| 13 | + assert curses.tigetnum("colors") > 2 |
| 14 | + OK = "\x1b[1;%dm[ OK ]\x1b[0m" % (30 + curses.COLOR_GREEN) |
| 15 | + FAIL = "\x1b[1;%dm[FAIL]\x1b[0m" % (30 + curses.COLOR_RED) |
| 16 | +except: |
| 17 | + OK = '[ OK ]' |
| 18 | + FAIL = '[FAIL]' |
| 19 | + |
| 20 | +try: |
| 21 | + import importlib |
| 22 | +except ImportError: |
| 23 | + print(FAIL, "Python version 3.4 is required," |
| 24 | + " but %s is installed." % sys.version) |
| 25 | + |
| 26 | + |
| 27 | +def import_version(pkg, min_ver, fail_msg=""): |
| 28 | + mod = None |
| 29 | + try: |
| 30 | + mod = importlib.import_module(pkg) |
| 31 | + if pkg in {'PIL'}: |
| 32 | + ver = mod.VERSION |
| 33 | + elif pkg in {'xlrd'}: |
| 34 | + ver = mod.__VERSION__ |
| 35 | + else: |
| 36 | + ver = mod.__version__ |
| 37 | + if Version(ver) < min_ver: |
| 38 | + print(FAIL, "%s version %s or higher required, but %s installed." |
| 39 | + % (lib, min_ver, ver)) |
| 40 | + else: |
| 41 | + print(OK, '%s version %s' % (pkg, ver)) |
| 42 | + except ImportError: |
| 43 | + print(FAIL, '%s not installed. %s' % (pkg, fail_msg)) |
| 44 | + return mod |
| 45 | + |
| 46 | + |
| 47 | +# first check the python version |
| 48 | +print('Using python in', sys.prefix) |
| 49 | +print(sys.version) |
| 50 | +pyversion = Version(sys.version) |
| 51 | +if pyversion >= "3": |
| 52 | + if pyversion < "3.6": |
| 53 | + print(FAIL, "Python version 3.6 is required," |
| 54 | + " but %s is installed." % sys.version) |
| 55 | +else: |
| 56 | + print(FAIL, "Python 3 is required, but %s is installed." % sys.version) |
| 57 | + |
| 58 | +print() |
| 59 | +requirements = {'numpy': "1.9", 'matplotlib': "2.0", |
| 60 | + 'pandas': "1.1", 'xarray': '0.16', |
| 61 | + 'geopandas': '0.8', 'rasterio': '1.1', |
| 62 | + 'owslib': '0.19', 'fsspec': '0.8', |
| 63 | + 's3fs': '0.3', 'pyproj': '2.4'} |
| 64 | + |
| 65 | +# now the dependencies |
| 66 | +for lib, required_version in list(requirements.items()): |
| 67 | + import_version(lib, required_version) |
0 commit comments