In [ ]:
import logging, sys, inspect
from os.path import dirname, abspath
from optparse import OptionParser


def log_error_and_exit(error_message):
  logging.error(error_message)
  raise SystemExit


#try to import setuptools
try:
  from setuptools import setup, Extension
  from setuptools.command import easy_install
except ImportError:
  log_error_and_exit("""setuptools is not installed for \"""" + sys.executable +
                     """\"
Follow this link for installing instructions :
https://pypi.python.org/pypi/setuptools
make sure you use \"""" + sys.executable + """\" during the installation""")

from pkg_resources import parse_version


def notinstalled(modulename):
  return modulename + """ could not be imported for \"""" + sys.executable + """\"
Set PYTHONPATH to the output of this command \"make print-OR_TOOLS_PYTHONPATH\" before running the examples"""


def wrong_module(module_file, modulename):
  return """
The python examples are not importing the """ + modulename + """ module from the sources.
Remove the site-package that contains \"""" + module_file + """\", either manually or by using pip, and rerun this script again."""


# Returns the n_th parent of file
def n_dirname(n, file):
  directory = file
  for x in range(0, n):
    directory = dirname(directory)
  return directory