From: Fuzzyman <fuz...@vo...> - 2006-02-13 09:28:17
|
Thomas Heller wrote: > Michael Foord wrote: >> Hello all, >> >> I'm trying to use zipimport to extract code objects from the >> library.zip that py2exe generates. Unfortunately it fails. :-( >> >> The code looks like : >> >> for entry in sys.path: >> if entry.endswith('.zip') and not mods: >> # Need to use zipimporter >> import zipimport >> try: >> z = zipimport.zipimporter(entry) >> except zipimport.ZipImportError: >> # not a valid zipfile >> # we'll try this path as a directory >> pass >> else: >> try: >> return z.get_code(mod) >> except zipimport.ZipImportError: >> continue >> >> This bit works fine : >> >> z = zipimport.zipimporter(entry) >> >> But the get_code fails. Any reason why this should be, and ideas for >> a workaround ? > > Hm, what errors do you get? This script seems to work for me: > > import sys > import urllib > > for entry in sys.path: > if entry.endswith('.zip'): > # Need to use zipimporter > import zipimport > try: > z = zipimport.zipimporter(entry) > except zipimport.ZipImportError: > # not a valid zipfile > # we'll try this path as a directory > pass > else: > print z.get_code("urllib") > > > it prints: > > <code object ? at 00A859E0, file "urllib.pyc", line 23> > Hmmm... It's specifically 'pdb' I'm trying it with. Yesterday I built a new version of Movable Python which supports the '-m' command line option for running modules. It works for modules not contained in the zipfile but for pdb, bombed out on the : try: codeobj = z.get_code(mod) except zipimport.ZipImportError: # It didn't work ! Unfortunately I'm actually using Movable Python here, and didn't bring the new version here. (And Movable Python doesn't yet support py2exe, so I can't get it to build the newer version here !). This means I can't report the *actual* traceback. When I try this code on its own it works ! (Running under Movable Python 1.0.0). However, if I use it from an interactive interpreter session I get the following traceback : (modulefinder below returns the code object) In [11] D:\movpy >>> a = modulefinder('pdb') In [12] D:\movpy >>> exec a --------------------------------------------------------------------------- exceptions.NameError Traceback (most recent call last) D:\movpy\<ipython console> D:\movpy\pdb.pyc D:\movpy\pdb.pyc in Pdb() NameError: name 'cmd' is not defined Weird but possibly not significant. This means that modulefinder *works* from the interpreter, but fails when run from my main code. I'll have to play some more tonight and see exactly what the traceback says. Anyway, thanks for trying it Thomas. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml > Thomas > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log > files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 > _______________________________________________ > Py2exe-users mailing list > Py2...@li... > https://lists.sourceforge.net/lists/listinfo/py2exe-users > |