[python-win32] Re: Problems with py2exe on Biopython-based script

Thomas Heller theller at python.net
Fri Jan 30 11:01:57 EST 2004


Leighton Pritchard <lpritc at scri.sari.ac.uk> writes:

> Many thanks for the help, Thomas - I think my problem is solved with
> changes only to Bio/__init__.py; no modifications were required to
> FormatIO.py in the end.
>

> I've taken your advice, and replaced the original registry import code
> (lines 52-55) of Bio/__init__.py with the following:
>
> ####
>
> # Import code changed to allow for compilation with py2exe from distutils
>      config_imports = __import__("Bio.config", {}, {}, ["Bio"])  #
>      Import Bio.config
>      if hasattr(config_imports, '__loader__'):                   # Is
>      it in zipfile?
>          zipfiles = __import__("Bio.config", {}, {}, ["Bio"]).__loader__._files
>          x = [zipfiles[file][0] for file in zipfiles.keys() \    # Get
>          only Bio.config modules
>               if 'Bio\\config' in file]
>          x = [name.split('\\')[-1] for name in x]                # Get
>          module name
>          x = map(lambda x: x[:-4], x)                            #
>          chop off '.pyc'
>      else:                           # Not in zipfile, get files normally
>          x = os.listdir(
>              os.path.dirname(config_imports.__file__))
>          x = filter(lambda x: not x.startswith("_") and x.endswith(".py"), x)
>          x = map(lambda x: x[:-3], x)            # chop off '.py'
>
> ###
>
> Which seems to work.

You could suggest the biopython guys to change their code for the benfit
of future users ;-)

And, it would be most appreciated if you would create a page in the
py2exe wiki outlining the principal problem and the solution:

<http://starship.python.net/crew/theller/moin.cgi/Py2Exe>

TIA,

Thomas




More information about the Python-win32 mailing list