# Buggy code
def _locate(path: str) -> Union[type, Callable[..., Any]]:
    """
    Locate an object by name or dotted path, importing as necessary.
    This is similar to the pydoc function `locate`, except that it checks for
    the module from the given path from back to front.
    """
    if path == "":
        raise ImportError("Empty path")
    import builtins
    from importlib import import_module

    parts = [part for part in path.split(".") if part]
    module = None
    for n in reversed(range(len(parts))):
        try:
            mod = ".".join(parts[:n])
            module = import_module(mod)
        except Exception as e:
            if n == 0:
                raise ImportError(f"Error loading module '{path}'") from e
            continue
        if module:
            break
    if module:
        obj = module
    else:
        obj = builtins
    for part in parts[n:]:
        if not hasattr(obj, part):
            raise ImportError(f"Could not locate '{path}'")
        obj = getattr(obj, part)
    if isinstance(obj, type):
        obj_type: type = obj
        return obj_type
    elif callable(obj):
        obj_callable: Callable[..., Any] = obj
        return obj_callable
    else:
        # dummy case
        raise ValueError(f"Invalid type ({type(obj)}) found for {path}")


# Traceback (ImportError)
Traceback (most recent call last):
File "C:\Users\khoa\Anaconda3\envs\py3\lib\site-packages\hydra\utils.py", line 33, in call
type_or_callable = _locate(cls)
File "C:\Users\khoa\Anaconda3\envs\py3\lib\site-packages\hydra\_internal\utils.py", line 520, in _locate
raise ImportError(f"Could not locate '{path}'")
ImportError: Could not locate 'code.example_code.sample_fucntion'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "my_app.py", line 15, in my_app
python_class = hydra.utils.instantiate(cfg.code)
File "C:\Users\khoa\Anaconda3\envs\py3\lib\site-packages\hydra\utils.py", line 40, in call
raise HydraException(f"Error calling '{cls}' : {e}") from e
hydra.errors.HydraException: Error calling 'code.example_code.sample_fucntion' : Could not locate 'code.example_code.sample_fucntion'

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.```

##Expected Behavior
It should show I'm missing the `pytorch_lightning` package, instead of the error above

## System information
- **Hydra Version** :  rc2 and previous
- **Python version** : 3.7
- **Operating system** : linux

# Fixed code
def _locate(path: str) -> Union[type, Callable[..., Any]]:
    """
    Locate an object by name or dotted path, importing as necessary.
    This is similar to the pydoc function `locate`, except that it checks for
    the module from the given path from back to front.
    """
    if path == "":
        raise ImportError("Empty path")
    import builtins
    from importlib import import_module

    parts = [part for part in path.split(".") if part]
    module = None
    for n in reversed(range(len(parts))):
        try:
            mod = ".".join(parts[:n])
            module = import_module(mod)
        except Exception as e:
            if n == 0:
                raise ImportError(f"Error loading module '{path}'") from e
            continue
        if module:
            break
    if module:
        obj = module
    else:
        obj = builtins
    for part in parts[n:]:
        mod = mod + "." + part
        if not hasattr(obj, part):
            try:
                import_module(mod)
            except Exception as e:
                raise ImportError(
                    f"Encountered error: `{e}` when loading module '{path}'"
                ) from e
        obj = getattr(obj, part)
    if isinstance(obj, type):
        obj_type: type = obj
        return obj_type
    elif callable(obj):
        obj_callable: Callable[..., Any] = obj
        return obj_callable
    else:
        # dummy case
        raise ValueError(f"Invalid type ({type(obj)}) found for {path}")