{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from __future__ import print_function\n", "from distutils.version import LooseVersion as Version\n", "import sys\n", "\n", "\n", "try:\n", " import curses\n", " curses.setupterm()\n", " assert curses.tigetnum(\"colors\") > 2\n", " OK = \"\\x1b[1;%dm[ OK ]\\x1b[0m\" % (30 + curses.COLOR_GREEN)\n", " FAIL = \"\\x1b[1;%dm[FAIL]\\x1b[0m\" % (30 + curses.COLOR_RED)\n", "except:\n", " OK = '[ OK ]'\n", " FAIL = '[FAIL]'\n", "\n", "try:\n", " import importlib\n", "except ImportError:\n", " print(FAIL, \"Python version 3.4 (or 2.7) is required,\"\n", " \" but %s is installed.\" % sys.version)\n", "\n", " \n", "def import_version(pkg, min_ver, fail_msg=\"\"):\n", " mod = None\n", " try:\n", " mod = importlib.import_module(pkg)\n", " if pkg in {'PIL'}:\n", " ver = mod.VERSION\n", " else:\n", " ver = mod.__version__\n", " if Version(ver) < min_ver:\n", " print(FAIL, \"%s version %s or higher required, but %s installed.\"\n", " % (lib, min_ver, ver))\n", " else:\n", " print(OK, '%s version %s' % (pkg, ver))\n", " except ImportError:\n", " print(FAIL, '%s not installed. %s' % (pkg, fail_msg))\n", " return mod\n", "\n", "\n", "# first check the python version\n", "print('Using python in', sys.prefix)\n", "print(sys.version)\n", "pyversion = Version(sys.version)\n", "if pyversion >= \"3\":\n", " if pyversion < \"3.4\":\n", " print(FAIL, \"Python version 3.4 (or 2.7) is required,\"\n", " \" but %s is installed.\" % sys.version)\n", "elif pyversion >= \"2\":\n", " if pyversion < \"2.7\":\n", " print(FAIL, \"Python version 2.7 is required,\"\n", " \" but %s is installed.\" % sys.version)\n", "else:\n", " print(FAIL, \"Unknown Python version: %s\" % sys.version)\n", "\n", "print()\n", "requirements = {'numpy': \"1.6.1\", 'scipy': \"0.9\", 'matplotlib': \"1.0\",\n", " 'IPython': \"3.0\", 'sklearn': \"0.15\",\n", " 'watermark': \"1.3.1\",\n", " 'yaml': \"3.11\", 'PIL': \"1.1.7\"}\n", "\n", "# now the dependencies\n", "for lib, required_version in list(requirements.items()):\n", " import_version(lib, required_version)\n", "\n", "# pydot is a bit different\n", "import_version(\"pydot\", \"0\", fail_msg=\"pydot is not installed.\"\n", " \"It is not required but you will miss out on some plots.\"\n", " \"\\nYou can install it using \"\n", " \"'pip install pydot' on python2, and 'pip install \"\n", " \"git+https://github.com/nlhepler/pydot.git' on python3.\");\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.1" } }, "nbformat": 4, "nbformat_minor": 0 }