diff --git a/setup.py b/setup.py index 913b2e78362b7..39dfe2a45231d 100755 --- a/setup.py +++ b/setup.py @@ -119,22 +119,42 @@ def configuration(parent_package='', top_path=None): numpy_min_version = '1.6.1' -def is_scipy_installed(): +def get_scipy_status(): + """ + Returns a dictionary containing a boolean specifying whether SciPy + is up-to-date, along with the version string (empty string if + not installed). + """ + scipy_status = {} try: import scipy - return parse_version(scipy.__version__) >= parse_version( - scipy_min_version) + scipy_version = scipy.__version__ + scipy_status['up_to_date'] = parse_version( + scipy_version) >= parse_version(scipy_min_version) + scipy_status['version'] = scipy_version except ImportError: - return False - - -def is_numpy_installed(): + scipy_status['up_to_date'] = False + scipy_status['version'] = "" + return scipy_status + + +def get_numpy_status(): + """ + Returns a dictionary containing a boolean specifying whether NumPy + is up-to-date, along with the version string (empty string if + not installed). + """ + numpy_status = {} try: import numpy - return parse_version(numpy.__version__) >= parse_version( - numpy_min_version) + numpy_version = numpy.__version__ + numpy_status['up_to_date'] = parse_version( + numpy_version) >= parse_version(numpy_min_version) + numpy_status['version'] = numpy_version except ImportError: - return False + numpy_status['up_to_date'] = False + numpy_status['version'] = "" + return numpy_status def setup_package(): @@ -184,22 +204,38 @@ def setup_package(): metadata['version'] = VERSION else: - if is_numpy_installed() is False: - raise ImportError("An up-to-date version of Numerical Python " - "(NumPy) is not installed.\n" - "scikit-learn requires NumPy >= {0}.\n" - .format(numpy_min_version) + - "Installation instructions are available " - "on the scikit-learn website: " - "http://scikit-learn.org/stable/install.html\n") - if is_scipy_installed() is False: - raise ImportError("An up-to-date version of Scientific Python " - "(SciPy) is not installed.\n" - "scikit-learn requires SciPy >= {0}.\n" - .format(scipy_min_version) + - "Installation instructions are available " - "on the scikit-learn website: " - "http://scikit-learn.org/stable/install.html\n") + numpy_status = get_numpy_status() + numpy_req_str = "scikit-learn requires NumPy >= {0}.\n".format( + numpy_min_version) + scipy_status = get_scipy_status() + scipy_req_str = "scikit-learn requires SciPy >= {0}.\n".format( + scipy_min_version) + + instructions = ("Installation instructions are available on the " + "scikit-learn website: " + "http://scikit-learn.org/stable/install.html\n") + + if numpy_status['up_to_date'] is False: + if numpy_status['version']: + raise ImportError("Your installation of Numerical Python " + "(NumPy) {0} is out-of-date.\n{1}{2}" + .format(numpy_status['version'], + numpy_req_str, instructions)) + else: + raise ImportError("Numerical Python (NumPy) is not " + "installed.\n{0}{1}" + .format(numpy_req_str, instructions)) + if scipy_status['up_to_date'] is False: + if scipy_status['version']: + raise ImportError("Your installation of Scientific Python " + "(SciPy) {0} is out-of-date.\n{1}{2}" + .format(scipy_status['version'], + scipy_req_str, instructions)) + else: + raise ImportError("Scientific Python (SciPy) is not " + "installed.\n{0}{1}" + .format(scipy_req_str, instructions)) + from numpy.distutils.core import setup metadata['configuration'] = configuration