def setup_env():
    # Try to import the appengine code from the system path.
    try:
        from google.appengine.api import apiproxy_stub_map
    except ImportError:
        for k in [k for k in sys.modules if k.startswith('google')]:
            del sys.modules[k]

        # Not on the system path. Build a list of alternative paths where it
        # may be. First look within the project for a local copy, then look for
        # where the Mac OS SDK installs it.
        paths = [os.path.join(PROJECT_DIR, '.google_appengine'),
                 os.environ.get('APP_ENGINE_SDK'),
                 '/usr/local/google_appengine',
                 '/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine']
        for path in os.environ.get('PATH', '').split(os.pathsep):
            path = path.rstrip(os.sep)
            if path.endswith('google_appengine'):
                paths.append(path)
        if os.name in ('nt', 'dos'):
            path = r'%(PROGRAMFILES)s\Google\google_appengine' % os.environ
            paths.append(path)
        # Loop through all possible paths and look for the SDK dir.
        sdk_path = None
        for path in paths:
            if not path:
                continue
            path = os.path.expanduser(path)
            path = os.path.realpath(path)
            if os.path.exists(path):
                sdk_path = path
                break
        if sdk_path is None:
            # The SDK could not be found in any known location.
            sys.stderr.write('The Google App Engine SDK could not be found!\n'
                             "Make sure it's accessible via your PATH "
                             "environment and called google_appengine.\n")
            sys.exit(1)
        # Add the SDK and the libraries within it to the system path.
        extra_paths = [sdk_path]
        lib = os.path.join(sdk_path, 'lib')
        # Automatically add all packages in the SDK's lib folder:
        for name in os.listdir(lib):
            root = os.path.join(lib, name)
            subdir = name
            # Package can be under 'lib/<pkg>/<pkg>/' or 'lib/<pkg>/lib/<pkg>/'
            detect = (os.path.join(root, subdir), os.path.join(root, 'lib', subdir))
            for path in detect:
                if os.path.isdir(path):
                    extra_paths.append(os.path.dirname(path))
                    break
            else:
                if name == 'webapp2':
                    extra_paths.append(root)
        sys.path = extra_paths + sys.path
        from google.appengine.api import apiproxy_stub_map

    setup_project()
    from .utils import have_appserver
    if have_appserver:
        # App Engine's threading.local is broken
        setup_threading()
    elif not os.path.exists(DATA_ROOT):
        os.mkdir(DATA_ROOT)
    setup_logging()

    if not have_appserver:
        # Patch Django to support loading management commands from zip files
        from django.core import management
        management.find_commands = find_commands
Configures app engine environment for command-line apps.
dataset/ETHPy150Open adieu/djangoappengine/boot.py/setup_env