def _solve_pkg(main_globals):
<EOL>main_dir, search_path = _try_search_paths(main_globals)<EOL>if not search_path:<EOL><INDENT>_log_debug('<STR_LIT>' % main_dir)<EOL>return<EOL><DEDENT>pkg_str = path.relpath(main_dir, search_path).replace(path.sep, '<STR_LIT:.>')<EOL>site_pkgs = '<STR_LIT>'<EOL>if pkg_str.startswith(site_pkgs):<EOL><INDENT>pkg_str = pkg_str[len(site_pkgs):]<EOL><DEDENT>assert pkg_str<EOL>_log_debug('<STR_LIT>' % pkg_str)<EOL>try:<EOL><INDENT>if '<STR_LIT>' in main_globals['<STR_LIT>']:<EOL><INDENT>_log_debug('<STR_LIT>')<EOL>sys.modules[pkg_str] = sys.modules['<STR_LIT:__main__>']<EOL>sys.modules[pkg_str].__path__ = [main_dir]<EOL>parent_pkg_str = '<STR_LIT:.>'.join(pkg_str.split('<STR_LIT:.>')[:-<NUM_LIT:1>])<EOL>if parent_pkg_str:<EOL><INDENT>importlib.import_module(parent_pkg_str)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>_log_debug('<STR_LIT>' % pkg_str)<EOL>importlib.import_module(pkg_str)<EOL><DEDENT>main_globals['<STR_LIT>'] = pkg_str<EOL>return pkg_str<EOL><DEDENT>except ImportError as e:<EOL><INDENT>_print_exc(e)<EOL><DEDENT>
Find parent python path of __main__. From there solve the package
containing __main__, import it and set __package__ variable.

:param main_globals: globals dictionary in __main__