diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -711,7 +711,9 @@ class FrozenImporter: is_reload = fullname in sys.modules try: m = _call_with_frames_removed(_imp.init_frozen, fullname) - # Let our own module_repr() method produce a suitable repr. + # For frozen modules there is no sensible value for __file__. + # Thus per PEP 420 it can just be removed. A sensible repr + # can be produced by FrozenImporter.module_repr. del m.__file__ return m except: diff --git a/Lib/site.py b/Lib/site.py --- a/Lib/site.py +++ b/Lib/site.py @@ -435,11 +435,17 @@ def setcopyright(): builtins.credits = _Printer("credits", """\ Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands for supporting Python development. See www.python.org for more information.""") - here = os.path.dirname(os.__file__) + files, dirs = [], [] + # Not all modules are required to have a __file__ attribute. See + # PEP 420 for more details. + if hasattr(os, '__file__'): + here = os.path.dirname(os.__file__) + files.extend(["LICENSE.txt", "LICENSE"]) + dirs.extend([os.path.join(here, os.pardir), here, os.curdir]) + builtins.license = _Printer( "license", "See http://www.python.org/%.3s/license.html" % sys.version, - ["LICENSE.txt", "LICENSE"], - [os.path.join(here, os.pardir), here, os.curdir]) + files, dirs) class _Helper(object): diff --git a/Tools/freeze/freeze.py b/Tools/freeze/freeze.py --- a/Tools/freeze/freeze.py +++ b/Tools/freeze/freeze.py @@ -365,6 +365,10 @@ def main(): else: mf.load_file(mod) + # Alias "importlib._bootstrap" to "_frozen_importlib" so that the + # import machinery can bootstrap. + mf.modules["_frozen_importlib"] = mf.modules["importlib._bootstrap"] + # Add the main script as either __main__, or the actual module name. if python_entry_is_main: mf.run_script(scriptfile) diff --git a/Tools/freeze/makeconfig.py b/Tools/freeze/makeconfig.py --- a/Tools/freeze/makeconfig.py +++ b/Tools/freeze/makeconfig.py @@ -3,7 +3,7 @@ import sys # Write the config.c file -never = ['marshal', 'imp', '_ast', '__main__', 'builtins', +never = ['marshal', '_imp', '_ast', '__main__', 'builtins', 'sys', 'gc', '_warnings'] def makeconfig(infp, outfp, modules, with_ifdef=0):