-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathcheck_environment.py
68 lines (57 loc) · 2.18 KB
/
check_environment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# This script is adapted from Andreas Mueller:
# https://github.com/amueller/scipy-2018-sklearn/blob/master/check_env.ipynb
# and glemaitre: https://github.com/glemaitre/pyparis-2018-sklearn/blob/master/check_environment.py
import sys
# packaging is not in the stdlib, but should be available as dependency of
# some other package (eg jupyterlab, geopandas, ..)
from packaging import version
try:
import curses
curses.setupterm()
assert curses.tigetnum("colors") > 2
OK = "\x1b[1;%dm[ OK ]\x1b[0m" % (30 + curses.COLOR_GREEN)
FAIL = "\x1b[1;%dm[FAIL]\x1b[0m" % (30 + curses.COLOR_RED)
except:
OK = '[ OK ]'
FAIL = '[FAIL]'
try:
import importlib
except ImportError:
print(FAIL, "Python version 3.4 is required,"
" but %s is installed." % sys.version)
def import_version(pkg, min_ver, fail_msg=""):
mod = None
try:
mod = importlib.import_module(pkg)
if min_ver:
ver = mod.__version__
if version.parse(ver) < version.parse(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))
else:
print(OK, f"{pkg}")
except ImportError:
print(FAIL, '%s not installed. %s' % (pkg, fail_msg))
return mod
# first check the python version
print('Using python in', sys.prefix)
print(sys.version)
pyversion = version.parse(sys.version.split(" ")[0])
if pyversion >= version.parse("3"):
if pyversion < version.parse("3.10"):
print(FAIL, "Python version 3.10 is required,"
" but %s is installed." % sys.version)
else:
print(FAIL, "Python 3 is required, but %s is installed." % sys.version)
print()
requirements = {'numpy': "1.9", 'matplotlib': "2.0",
'pandas': "2.0", 'xarray': '0.16',
'geopandas': '1.0', 'rasterio': '1.1',
'owslib': '0.19', 'fsspec': '0.8',
's3fs': '0.3', 'pyproj': '2.4',
'hvplot.xarray': None}
# now the dependencies
for lib, required_version in list(requirements.items()):
import_version(lib, required_version)