|
94 | 94 |
|
95 | 95 | matplotlib was initially written by John D. Hunter (1968-2012) and is now
|
96 | 96 | developed and maintained by a host of others.
|
97 |
| -
|
98 |
| -Occasionally the internal documentation (python docstrings) will refer |
99 |
| -to MATLAB®, a registered trademark of The MathWorks, Inc. |
100 |
| -
|
101 | 97 | """
|
102 | 98 | # NOTE: This file must remain Python 2 compatible for the foreseeable future,
|
103 | 99 | # to ensure that we error out properly for existing editable installs.
|
104 | 100 | from __future__ import absolute_import, division, print_function
|
105 | 101 |
|
| 102 | +import pkg_resources |
| 103 | + |
| 104 | +try: |
| 105 | + pkg_resources.get_distribution("matplotlib") |
| 106 | +except pkg_resources.DistributionNotFound: |
| 107 | + # Running from source -- you're on your own. |
| 108 | + pass |
| 109 | +else: |
| 110 | + try: |
| 111 | + # Check that dependencies are correctly installed. |
| 112 | + pkg_resources.require("matplotlib") |
| 113 | + except pkg_resources.ResolutionError as e: |
| 114 | + raise ImportError("Matplotlib requires {}".format(e.req)) |
| 115 | + |
106 | 116 | import six
|
107 | 117 |
|
108 | 118 | import sys
|
|
120 | 130 | import atexit
|
121 | 131 | from collections import MutableMapping
|
122 | 132 | import contextlib
|
123 |
| -import distutils.version |
124 |
| -import distutils.sysconfig |
| 133 | +from distutils.version import LooseVersion |
125 | 134 | import functools
|
126 | 135 | import io
|
127 | 136 | import inspect
|
|
137 | 146 | import tempfile
|
138 | 147 | import warnings
|
139 | 148 |
|
| 149 | +if sys.version_info < (3, 5): # noqa: E402 |
| 150 | + raise ImportError(""" |
| 151 | +Matplotlib 3.0+ does not support Python 2.x, 3.0, 3.1, 3.2, 3.3, or 3.4. |
| 152 | +Beginning with Matplotlib 3.0, Python 3.5 and above is required. |
| 153 | +
|
| 154 | +See Matplotlib `INSTALL.rst` file for more information: |
| 155 | +
|
| 156 | + https://github.com/matplotlib/matplotlib/blob/master/INSTALL.rst |
| 157 | +
|
| 158 | +""") |
| 159 | + |
| 160 | +if sys.version_info < (3, 5): # noqa: E402 |
| 161 | + raise ImportError(""" |
| 162 | +Matplotlib 3.0+ does not support Python 2.x, 3.0, 3.1, 3.2, 3.3, or 3.4. |
| 163 | +Beginning with Matplotlib 3.0, Python 3.5 and above is required. |
| 164 | +
|
| 165 | +See Matplotlib `INSTALL.rst` file for more information: |
| 166 | +
|
| 167 | + https://github.com/matplotlib/matplotlib/blob/master/INSTALL.rst |
| 168 | +
|
| 169 | +""") |
| 170 | + |
| 171 | +from six.moves.urllib.request import urlopen |
| 172 | +from six.moves import reload_module as reload |
| 173 | + |
| 174 | +import numpy |
| 175 | + |
140 | 176 | # cbook must import matplotlib only within function
|
141 | 177 | # definitions, so it is safe to import from it here.
|
142 | 178 | from . import cbook
|
143 |
| -from matplotlib.cbook import ( |
| 179 | +from .cbook import ( |
144 | 180 | _backports, mplDeprecation, dedent, get_label, sanitize_sequence)
|
145 |
| -from matplotlib.rcsetup import defaultParams, validate_backend, cycler |
146 |
| - |
147 |
| -import numpy |
148 |
| -from six.moves.urllib.request import urlopen |
149 |
| -from six.moves import reload_module as reload |
| 181 | +from .rcsetup import defaultParams, validate_backend, cycler |
150 | 182 |
|
151 | 183 | # Get the version from the _version.py versioneer file. For a git checkout,
|
152 | 184 | # this is computed based on the number of commits since the last tag.
|
@@ -191,41 +223,11 @@ def compare_versions(a, b):
|
191 | 223 | a = a.decode('ascii')
|
192 | 224 | if isinstance(b, bytes):
|
193 | 225 | b = b.decode('ascii')
|
194 |
| - a = distutils.version.LooseVersion(a) |
195 |
| - b = distutils.version.LooseVersion(b) |
196 |
| - return a >= b |
| 226 | + return LooseVersion(a) >= LooseVersion(b) |
197 | 227 | else:
|
198 | 228 | return False
|
199 | 229 |
|
200 | 230 |
|
201 |
| -try: |
202 |
| - import dateutil |
203 |
| -except ImportError: |
204 |
| - raise ImportError("Matplotlib requires dateutil") |
205 |
| - |
206 |
| - |
207 |
| -if not compare_versions(six.__version__, '1.10'): |
208 |
| - raise ImportError( |
209 |
| - "Matplotlib requires six>=1.10; you have %s" % six.__version__) |
210 |
| - |
211 |
| - |
212 |
| -try: |
213 |
| - import pyparsing |
214 |
| -except ImportError: |
215 |
| - raise ImportError("Matplotlib requires pyparsing") |
216 |
| -else: |
217 |
| - if not compare_versions(pyparsing.__version__, '2.0.1'): |
218 |
| - raise ImportError( |
219 |
| - "Matplotlib requires pyparsing>=2.0.1; you have %s" |
220 |
| - % pyparsing.__version__) |
221 |
| - |
222 |
| - |
223 |
| -if not compare_versions(numpy.__version__, __version__numpy__): |
224 |
| - raise ImportError( |
225 |
| - "Matplotlib requires numpy>=%s; you have %s" % ( |
226 |
| - __version__numpy__, numpy.__version__)) |
227 |
| - |
228 |
| - |
229 | 231 | if not hasattr(sys, 'argv'): # for modpython
|
230 | 232 | sys.argv = [str('modpython')]
|
231 | 233 |
|
|
0 commit comments