[BioPython] Problems building biopython-based script with py2exe
Leighton Pritchard
lpritc at scri.sari.ac.uk
Fri Jan 30 06:52:34 EST 2004
Hi,
I have a workaround for this single build, though it's not ideal.
First, I replaced this line in Bio/__init__.py
x = os.listdir(
os.path.dirname(__import__("Bio.config", {}, {}, ["Bio"]).__file__))
with an explicit naming of each file in the library.zip file generated by
py2exe
x = ['.\\library.zip\\Bio\\config\\__init__.pyc',
'.\\library.zip\\Bio\\config\\_support.pyc',
'.\\library.zip\\Bio\\config\\FormatRegistry.pyc',
'.\\library.zip\\Bio\\config\\Registry.pyc']
and this solved problem number 2 below.
However, it introduced a new problem, in that FormatIO was trying to use a
(nonexistent?) module - Bio.formats, so I substituted the lines (54, 55)
import Bio
registery = Bio.formats
with
import Bio.formatdefs
registery = Bio.formatdefs
and this worked.
I then wrapped the original lines and their replacements in
try:
<original>
except:
<replacement>
and this seems fine, though might a fix of Bio.FormatIO, and one of
Bio.config__init__.py to account for imports from .zip files be required?
The missing modules 'mindy' and 'mxTextTools.__version__' in problem 1 seem
not to matter.
At 18:30 29/01/2004, you wrote:
>Hi,
>
>I have a script:
>
>### gentest.py
>
>from Bio import GenBank
>
>gi_list = ['AF339445', 'AF339444', 'AF339443', 'AF339442', 'AF339441']
>record_parser = GenBank.FeatureParser() # GenBank file parser
>ncbi_dict = GenBank.NCBIDictionary(parser = record_parser,
> database = "nucleotide") # Dict for
> accessing NCBI
>
>count = 1
>for accession in gi_list:
> print "Accessing GenBank for %s... (%d/%d)" % (accession, count,
> len(gi_list))
> try:
> record = ncbi_dict[accession] # Get record as SeqRecord
> RECORDS.append(record) # Put records in local list
> except:
> print "Accessing record %s failed" % accession
> count += 1
>
>###
>
>Which seems fairly simple and straightforward. However, when I try to
>turn this into a standalone executable with py2exe with the script below,
>the following problems occur:
>
>### setup.py
>
>from distutils.core import setup
>import py2exe, sys
>
>setup (name = "genbank2excel",
> version = "0.10",
> url = r'http://bioinf.scri.sari.ac.uk/lp/index.shtml',
> author = "Leighton Pritchard",
> console = ["gentest.py"])
>
>###
>
>Problem 1: apparently missing modules
>
>[partial stdout from python setup.py py2exe]
>[...]
>*** copy dlls ***
>copying E:\APPLIC~1\PYTHON~2\lib\site-packages\py2exe\run.exe ->
>E:\Data\CVSWorkspace\genbank2excel\genbank2excel\dist\gentest.exe
>The following modules appear to be missing
>['mindy', 'mxTextTools.__version__']
>
>Problem 2: The compiled program doesn't seem to like the os.listdir call
>in Bio/__init__.py line 52 (55 here because of some exploratory debugging
>lines I inserted), and doesn't think that the Bio/config folder in the
>library.zip file that py2exe generates is a file or directory...
>
>[complete stderr traceback from running the resulting gentest.exe]
>Traceback (most recent call last):
> File "gentest.py", line 1, in ?
> File "Bio\__init__.pyc", line 68, in ?
> File "Bio\__init__.pyc", line 55, in _load_registries
>WindowsError: [Errno 3] The system cannot find the path specified:
>'E:\\Data\\CVSWorkspace\\genbank2excel\\genbank2excel\\dist\\library.zip\\Bio\\config/*.*'
>
>Can any of you help or advise me on this? Am I missing something obvious?
>
>Thanks in advance,
Dr Leighton Pritchard AMRSC
D104, PPI, Scottish Crop Research Institute
Invergowrie, Dundee, DD2 5DA, Scotland, UK
E: lpritc at scri.sari.ac.uk
T: +44 (0)1382 568579 F: +44 (0)1382 568578
PGP key FEFC205C: http://www.keyserver.net http://pgp.mit.edu
More information about the BioPython
mailing list