|
19 | 19 | from contextlib import contextmanager |
20 | 20 | from IPython.core.display import HTML |
21 | 21 | import json |
22 | | -import matplotlib |
23 | | -import matplotlib.pylab as pylab |
24 | | -import matplotlib.pyplot as plt |
25 | | -import numpy as np |
26 | 22 | import os.path |
27 | 23 | import sys |
28 | 24 | import warnings |
29 | 25 | from kf_book.book_plots import set_figsize, reset_figsize |
30 | 26 |
|
31 | | -# version 1.4.3 of matplotlib has a bug that makes |
32 | | -# it issue a spurious warning on every plot that |
33 | | -# clutters the notebook output |
34 | | -if matplotlib.__version__ == '1.4.3': |
35 | | - warnings.simplefilter(action="ignore", category=FutureWarning) |
| 27 | +def test_installation(): |
| 28 | + try: |
| 29 | + import filterpy |
| 30 | + except: |
| 31 | + print("Please install FilterPy from the command line by running the command\n\t$ pip install filterpy\n\nSee chapter 0 for instructions.") |
36 | 32 |
|
37 | | -try: |
38 | | - matplotlib.style.use('default') |
39 | | -except: |
40 | | - pass |
| 33 | + try: |
| 34 | + import numpy |
| 35 | + except: |
| 36 | + print("Please install NumPy before continuing. See chapter 0 for instructions.") |
41 | 37 |
|
42 | | -def test_filterpy_version(): |
| 38 | + try: |
| 39 | + import scipy |
| 40 | + except: |
| 41 | + print("Please install SciPy before continuing. See chapter 0 for instructions.") |
| 42 | + |
| 43 | + try: |
| 44 | + import sympy |
| 45 | + except: |
| 46 | + print("Please install SymPy before continuing. See chapter 0 for instructions.") |
| 47 | + |
| 48 | + try: |
| 49 | + import matplotlib |
| 50 | + except: |
| 51 | + print("Please install matplotlib before continuing. See chapter 0 for instructions.") |
43 | 52 |
|
44 | | - import filterpy |
45 | 53 | from distutils.version import LooseVersion |
46 | 54 |
|
47 | 55 | v = filterpy.__version__ |
48 | 56 | min_version = "1.4.4" |
49 | 57 | if LooseVersion(v) < LooseVersion(min_version): |
50 | | - raise Exception("Minimum FilterPy version supported is {}.\n" |
51 | | - "Please install a more recent version.\n" |
52 | | - " ex: pip install filterpy --upgrade".format( |
| 58 | + print("Minimum FilterPy version supported is {}. " |
| 59 | + "Please install a more recent version.\n" |
| 60 | + " ex: pip install filterpy --upgrade".format( |
53 | 61 | min_version)) |
54 | 62 |
|
55 | 63 |
|
56 | | -# ensure that we have the correct filterpy loaded. This is |
| 64 | + v = matplotlib.__version__ |
| 65 | + min_version = "1.5.0" # this is really old!!! |
| 66 | + if LooseVersion(v) < LooseVersion(min_version): |
| 67 | + print("Minimum Matplotlib version supported is {}. " |
| 68 | + "Please install a more recent version.".format(min_version)) |
| 69 | + |
| 70 | + # require Python 2.7, or 3.5+ |
| 71 | + |
| 72 | + import sys |
| 73 | + v = sys.version_info |
| 74 | + if v.major > 3: |
| 75 | + # I guess if we are this far in the future it'll work? Who knows. |
| 76 | + # I just don't want to start getting issue reports when Python goes |
| 77 | + # to 4.0 |
| 78 | + return |
| 79 | + |
| 80 | + if (v.major == 2 and v.minor != 7) or (v.major == 3 and v.minor < 5): |
| 81 | + print('You must use Python version 2.7 or 3.5+ for the notebooks to work correctly') |
| 82 | + |
| 83 | + |
| 84 | + # need to add test for IPython. I think I want to be at 6, which also implies |
| 85 | + # Python 3, matplotlib 2+, etc. |
| 86 | + |
| 87 | +# ensure that we have the correct packages loaded. This is |
57 | 88 | # called when this module is imported at the top of each book |
58 | | -# chapter so the reader can see that they need to update FilterPy. |
59 | | -test_filterpy_version() |
| 89 | +# chapter so the reader can see that they need to update their environment. |
| 90 | +test_installation() |
| 91 | + |
| 92 | + |
| 93 | +# now that we've tested the existence of all packages go ahead and import |
| 94 | + |
| 95 | +import matplotlib |
| 96 | +import matplotlib.pylab as pylab |
| 97 | +import matplotlib.pyplot as plt |
| 98 | +import numpy as np |
| 99 | + |
| 100 | +# version 1.4.3 of matplotlib has a bug that makes |
| 101 | +# it issue a spurious warning on every plot that |
| 102 | +# clutters the notebook output |
| 103 | +if matplotlib.__version__ == '1.4.3': |
| 104 | + warnings.simplefilter(action="ignore", category=FutureWarning) |
| 105 | + |
| 106 | +try: |
| 107 | + matplotlib.style.use('default') |
| 108 | +except: |
| 109 | + pass |
| 110 | + |
60 | 111 |
|
61 | 112 | with warnings.catch_warnings(): |
62 | 113 | warnings.simplefilter("ignore", matplotlib.MatplotlibDeprecationWarning) |
|
0 commit comments