From a00c2407caed1fe61bdd92788f7a8eb27fcff969 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 21 Mar 2014 10:58:33 -0400 Subject: Issue #20884: Don't assume in importlib.__init__ that __file__ is defined. --- Lib/importlib/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'Lib/importlib/__init__.py') diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py index f6adc5cdcf..1bc99474f2 100644 --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -22,7 +22,12 @@ else: # a second copy of the module. _bootstrap.__name__ = 'importlib._bootstrap' _bootstrap.__package__ = 'importlib' - _bootstrap.__file__ = __file__.replace('__init__.py', '_bootstrap.py') + try: + _bootstrap.__file__ = __file__.replace('__init__.py', '_bootstrap.py') + except NameError: + # __file__ is not guaranteed to be defined, e.g. if this code gets + # frozen by a tool like cx_Freeze. + pass sys.modules['importlib._bootstrap'] = _bootstrap # To simplify imports in test code -- cgit v1.2.1