def setup_env(dev_appserver_version=1):
    """Configures GAE environment for command-line apps."""

    if dev_appserver_version not in (1, 2):
        raise Exception('Invalid dev_appserver_version setting, expected 1 or 2, got %s' % dev_appserver_version)

    # 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',
                 '/usr/local/opt/google-app-engine/share/google-app-engine',
                 '/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

        # The SDK could not be found in any known location.
        if sdk_path is None:
            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)

        # First add the found SDK to the path
        sys.path = [ sdk_path ] + sys.path

        # Then call fix_sys_path from the SDK
        try:
            from dev_appserver import fix_sys_path
        except __HOLE__:
            from old_dev_appserver import fix_sys_path

        if dev_appserver_version == 2:
            # emulate dev_appserver._run_file in devappserver2
            from dev_appserver import _PATHS
            sys.path = _PATHS._script_to_paths['dev_appserver.py'] + sys.path
        fix_sys_path()

    setup_project(dev_appserver_version)

    from djangoappengine.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
dataset/ETHPy150Open django-nonrel/djangoappengine/djangoappengine/boot.py/setup_env