From: Oisin M. <oi...@en...> - 2007-01-19 17:48:21
|
update: I came across another utility called tg2exe. I know it doesn't use py2exe, however I'm not having much luck with it either. I don't seem to be able to make any progress using either tools :( Has anyone ever had any luck make a standalone tg exe. I'll try post on turbogears instead in a day or so maybe if no one responds. Thanks, Oisin Oisin Mulvihill wrote: > Hello, > > I'm trying to build a standalone exe for a webapp project I've done > using turbogears > but I've not been having much luck. I've followed the advice here > "http://www.py2exe.org/index.cgi/ExeWithEggs", however I'm not sure I'm > implementing the solution correctly. > > In order to rule out problems with my webapp I created a simple > turbogears project > tgpy2exe and tried to build just it into an exe. This approach has > worked as I get the > following error when I tried to run the built exe: > > Owner@xanthau_vm [dist]> ./WebPresence.exe > Traceback (most recent call last): > File > "c:\Python24\lib\site-packages\py2exe-0.6.6-py2.4-win32.egg\py2exe\boot_common.py", > line 92, > in ? > import linecache > ImportError: No module named linecache > Traceback (most recent call last): > File "start-tgpy2exe.py", line 2, in ? > ImportError: No module named pkg_resources > Owner@xanthau_vm [dist]> > > My system Info: > > * python2.4 running on windows xp. > * py2exe 0.6.6 (installed via easy_install). > * turbogears 1.0 (installed via easy_install). > * build being run in cygwin, but I'm not using its python. > > > The following is my "setup.py" (also attached) which shows my current > approach. Thanks in advance, for any forthcoming pearls of wisdom... > > Oisin > > > setup.py: > > # > # I'm following/implementing the rough approach here: > http://www.py2exe.org/index.cgi/ExeWithEggs > # > # 1. unpack zipped eggs, because I believe py2exe chokes on them when > resolving dependencies > # 2. keep track of the top level packages in the eggs > # 3. add all of the files in the eggs to the data_files, so that the > eggs are installed along side the main exe > # 4. build the exe > # 5. generate a new library.zip that does not include anything in the > top level packages found in step 2 > # > # > import os > import sys > import zipfile > import subprocess > > # setuptools must be imported first before py2exe > import setuptools > import py2exe > from setuptools import setup, find_packages > from turbogears.finddata import find_package_data > > > execfile(os.path.join("tgpy2exe", "release.py")) > > > # Here's steps 1 and 2: > import pkg_resources > from setuptools.archive_util import unpack_archive > > eggdir = r"c:\Python24\Lib\site-packages" > > eggs = pkg_resources.require("TurboGears") > > for egg in eggs: > if os.path.isdir(egg.location): > sys.path.insert(0, egg.location) > continue > unpack_archive(egg.location, eggdir) > > eggfiledirs = [] > eggpacks = set() > eggspth = open("build/eggs.pth", "w") > for egg in eggs: > print egg > eggspth.write(os.path.basename(egg.location)) > eggspth.write("\n") > eggpacks.update(egg.get_metadata_lines("top_level.txt")) > eggfiledirs.append(egg.location) > eggspth.close() > eggpacks.remove("pkg_resources") > > > > class WebPresenceTarget(object): > """Standalone exe for testing. > """ > def __init__(self): > self.name = 'Web Presence' > self.script = 'start-tgpy2exe.py' > self.dest_base = 'WebPresence' > self.description='Web Presence for the xyz system (exe)' > > data = find_package_data(where='tgpy2exe', package='tgpy2exe') > > > # A failed attempt at step 3. > data_files = [ > # > # Find package data didn't work, it seems to look for stuff > # not part of the package: > # > # *** copy data files *** > # creating z:\aam\tgpy2exe\dist\turbogears > # error: can't copy 'turbogears.win32com.test': doesn't exist or not > a regular file > # > # ('turbogears', find_package_data(where=eggdir, package='turbogears')), > # > ] > > # Step 4. > setup( > name="tgpy2exe", > > version=version, > > install_requires = [ > "TurboGears >= 1.0", > ], > > console = [ > WebPresenceTarget(), > ], > > packages=find_packages(), > > data_files = data_files, > > package_data = data, > ) > > > > # Step 5: > import zipfile > > oldzipfile = "dist/library.zip" > newzipfile = "dist/small-library.zip" > > oldzip = zipfile.ZipFile(oldzipfile, "r") > newzip = zipfile.ZipFile(newzipfile, "w", zipfile.ZIP_STORED) > > for entry in oldzip.infolist(): > delim = entry.filename.find("/") > if delim == -1: > delim = entry.filename.find(".") > if delim > -1: > if entry.filename[0:delim] in eggpacks: > print "Skipping %s, it's in the egg" % (entry.filename) > continue > newzip.writestr(entry, oldzip.read(entry.filename)) > > newzip.close() > oldzip.close() > > os.remove(oldzipfile) > os.rename(newzipfile, oldzipfile) > > > > # My attempt at getting round step 3 by just copying in the > # missing egg files directly. > # > # Add the required egg files (cygwin needed) to the library > # zip file, not the best approach: > # > # > def c(cmds, **opts): > for cmd in cmds: > print cmd > app_process = subprocess.Popen( > args=cmd, > shell=True, > **opts > ) > out, err = app_process.communicate() > print "%s %s" % (out or "", err or "") > > if app_process.returncode > 0: > print "Error: return code %s " % app_process.returncode > sys.exit(1) > > > cmds = [ > "unzip -o dist/library.zip -d dist/library", > "rm -f dist/library.zip", > ] > c(cmds) > > > # Copy the decompressed egg directories: > for file_or_dir in eggfiledirs: > c(["cp -r %s dist/library" % file_or_dir]) > > > # Copy required setuptools, for the pkg_resources, so the eggs can be found: > cmds = [ > "cp -r %s\setuptools-0.6c5-py2.4.egg dist/library" % eggdir, > "cp -r %s\setuptools.pth dist/library" % eggdir, > "cp -r %s\easy-install.pth dist/library" % eggdir, > ] > c(cmds) > > > # Rebuild the library with the updated content: > c(["zip -qr library.zip *"], cwd="dist") > > > > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Py2exe-users mailing list > Py2...@li... > https://lists.sourceforge.net/lists/listinfo/py2exe-users > > -- Oisin Mulvihill Engines Of Creation Ltd. Mobile: +44-(0)-7891538345 Email: oi...@en... Web: http://www.enginesofcreation.ie Email: oi...@en... Web: http://www.enginesofcreationsoftware.com |