[Python-Dev] Python 3.4 change in importlib/__init__.py breaking cxFreeze?
R. David Murray
rdmurray at bitdance.com
Mon Mar 10 16:06:26 CET 2014
On Mon, 10 Mar 2014 23:25:17 +1000, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 10 Mar 2014 19:15, "Jurko GospodnetiÄ" <jurko.gospodnetic at pke.hr> wrote:
> >
> > Hi all.
> >
> > Python 3.4 introduced a change to Lib/importlib/__init__.py that added
> the following code to it:
> >
> >> else:
> >> # importlib._bootstrap is the built-in import, ensure we don't create
> >> # a second copy of the module.
> >> _bootstrap.__name__ = 'importlib._bootstrap'
> >> _bootstrap.__package__ = 'importlib'
> >> _bootstrap.__file__ = __file__.replace('__init__.py',
> '_bootstrap.py')
> >> sys.modules['importlib._bootstrap'] = _bootstrap
> >
> >
> > When attempting to use cxFreeze on a project, using Python 3.4. we ran
> into a problem with '__file__' identifier not being defined.
> >
> > Could this be a python bug? Why is this code expecting the module
> loaded from importlib/__init__.py to always have a __file__ identifier?
> What is supposed to happen when that code gets loaded from a ZIP archive?
>
> __file__ is expected to always be set (including when loaded from a zipfile
> - in that case it's the zipfile name concatenated with the path within the
> zip file). If it isn't set, there's a buggy loader involved somewhere that
> isn't setting it properly.
I noticed while using cx_Freeze that __file__ is not set on the main
module that cx_Freeze calls (and I found that very annoying :). I'm
guessing this is a cx_Freeze artifact and will need to be fixed in
cx_Freeze.
--David
More information about the Python-Dev
mailing list