Hi Giovanni,

Thanks for the response.

I just checked out svn trunk and tried but it still failed.
  File "/home/feng/dev/pyinstaller-svn/pyinstaller/iu.py", line 532,
in doimport
    del sys.modules[fqname]
KeyError: 'bsddb'

even when I changed the iu.py: except KeyError: to except:
it still didn't work.

However, from your explanation, I made the following change:
                            try:
                                if fqname in sys.modules:
                                    # TODO: weird, except KeyError
doesn't
                                    #       catch KeyError here
                                    del sys.modules[fqname]
                            except KeyError:
and it worked. Somehow this 'except KeyError' just doesn't work here.
I did one more experiment in normal interactive shell:
>>> import bsddb
>>> del sys.modules['bsddb']
>>> del sys.modules['bsddb']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'bsddb'
>>> try:
...   del sys.modules['bsddb']
... except KeyError:
...   pass
...
>>>
So I don't know why. Maybe it's a python language bug? Or something
else special inside pyinstaller packaged binary environment

So at least, by the above change (add the if fqname in sys.modules
check), the pyinstaller works for me now.

Cheers!

Feng


On Mar 31, 5:35 am, Giovanni Bajo <[email protected]> wrote:
> On Mon, 2010-03-29 at 23:48 -0700, Feng wrote:
> > Hi, could somebody help? Thanks in advance! - Feng
>
> > I use Mako in my python codes. However, when I used pyinstaller to
> > build --onefile. The result binary failed with below message:
>
> > """
> >   File "bin/template-mako-module/highlight.html.py", line 2, in
> > <module>
> >     from mako import runtime, filters, cache
> >   File "/home/feng/dev/pyinstaller-1.4/iu.py", line 477, in importHook
> >     mod = self.doimport(nm, ctx, ctx+'.'+nm)
> >   File "/home/feng/dev/pyinstaller-1.4/iu.py", line 521, in doimport
> >     exec co in mod.__dict__
> >   File "/home/feng/runs/r2010-03-26/bin/build/pyi.linux2/backend.py/
> > outPYZ1.pyz/mako.cache", line 4, in <module>
> >   File "/home/feng/dev/pyinstaller-1.4/iu.py", line 477, in importHook
> >     mod = self.doimport(nm, ctx, ctx+'.'+nm)
> >   File "/home/feng/dev/pyinstaller-1.4/iu.py", line 521, in doimport
> >     exec co in mod.__dict__
> >   File "/home/feng/runs/r2010-03-26/bin/build/pyi.linux2/backend.py/
> > outPYZ1.pyz/beaker.cache", line 13, in <module>
> >   File "/home/feng/dev/pyinstaller-1.4/iu.py", line 436, in importHook
> >     mod = _self_doimport(nm, ctx, fqname)
> >   File "/home/feng/dev/pyinstaller-1.4/iu.py", line 521, in doimport
> >     exec co in mod.__dict__
> >   File "/home/feng/runs/r2010-03-26/bin/build/pyi.linux2/backend.py/
> > outPYZ1.pyz/beaker.container", line 2, in <module>
> >   File "/home/feng/dev/pyinstaller-1.4/iu.py", line 436, in importHook
> >     mod = _self_doimport(nm, ctx, fqname)
> >   File "/home/feng/dev/pyinstaller-1.4/iu.py", line 521, in doimport
> >     exec co in mod.__dict__
> >   File "/home/feng/runs/r2010-03-26/bin/build/pyi.linux2/backend.py/
> > outPYZ1.pyz/anydbm", line 54, in <module>
> >   File "/home/feng/dev/pyinstaller-1.4/iu.py", line 436, in importHook
> >     mod = _self_doimport(nm, ctx, fqname)
> >   File "/home/feng/dev/pyinstaller-1.4/iu.py", line 521, in doimport
> >     exec co in mod.__dict__
> >   File "bin/build/pyi.linux2/backend.py/outPYZ1.pyz/dbhash", line 8,
> > in <module>
> >   File "/home/feng/dev/pyinstaller-1.4/iu.py", line 436, in importHook
> >     mod = _self_doimport(nm, ctx, fqname)
> >   File "/home/feng/dev/pyinstaller-1.4/iu.py", line 531, in doimport
> >     del sys.modules[fqname]
> > KeyError: 'bsddb'
> > """
>
> It looks like bsddb.py and dbhash.py in standard library contains some
> leftovers which are not needed anymore. In fact:
>
> try:
>     import bsddb
> except ImportError:
>     # prevent a second import of this module from spuriously succeeding
>     del sys.modules[__name__]
>     raise
>
> Since Python 2.4, there is no need to remove itself from sys.modules in
> case of ImportError: it is done automatically by Python itself.
>
> So what happens is that PyInstaller too tries to remove the module from
> sys.modules, and fails because the module has already cleaned up after
> itself. Basically, we should be lenient and ignore the error.
>
> I have committed this change in SVN (revision [815]). Can you please try
> again with PyInstaller from SVN trunk?
>
> --
> Giovanni Bajo   ::  [email protected]
> Develer S.r.l.  ::  http://www.develer.com
>
> My Blog:http://giovanni.bajo.it
> Last post: C++ and copy-on-write data structures

-- 
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyinstaller?hl=en.

Reply via email to