this is a non trivial task because of some of TG's C dependencies that is why http://cheeseshop.python.org/pypi/tg2exe/0.2 was born
On 1/31/07, Oisin Mulvihill <[EMAIL PROTECTED]> wrote: > > > Hello, > > I was hoping that this problem might have been magically solved > when I was on holiday ;) > > I've come up with a hack/fix which works consistently for me using > tg2exe. I can't however do anything to get py2exe to work properly > with turbogears. > > The problem seems to be with the "easy_install.pth" on my system. > All entries in it mention filenames that are lower case. When the > "pkg_resources.py" looked for packages it did not find TurboGears > and other filenames as the exact package couldn't be found. > > This only seems to be a problem with when I run the python that > tg2exe gathers together. The system installed python doesn't suffer > from this problem. I really don't know why this should be the case. > Could this be a bug in setuptools that hasn't occurred before? > > > The hack solution for tg2exe: > > * Decompress eggs in the system site-packages dir so there are no > eggs in zip format. > > * tg-admin makexe > > * Open the "dist\Lib\site-packages" > > * Delete the modules tg-admin makexe has gathered that we wil use > eggs for: > > cherrypy, dispatch, elementtree, formencode, kid, paste, > protocols, py2exe, setuptools, simplejson, turbogears, > turbojson > > * Copy in the eggs (in zip format download from tg site): > > Cheetah-1.0-py2.4-win32.egg > CherryPy-2.2.1-py2.4.egg > DOMinclude-1.0-py2.4.egg > LightBox-2.0-py2.4.egg > Paste-0.9.7-py2.4.egg > PasteDeploy-0.9.6-py2.4.egg > PyProtocols-1.0a0dev_r2082-py2.4-win32.egg > ruledispatch-0.5a0.dev_r2115-py2.4-win32.egg > SQLObject-0.7.1dev_r1860-py2.4.egg > TurboGears-1.0.1-py2.4.egg > TurboJson-1.0-py2.4.egg > TurboKid-0.9.8-py2.4.egg > cElementTree-1.0.5_20051216-py2.4-win32.egg > configobj-4.3.2-py2.4.egg > elementtree-1.2.6-py2.4.egg > kid-0.9.3-py2.4.egg > simplejson-1.3-py2.4.egg > setuptools-0.6c5-py2.4.egg > FormEncode-0.6-py2.4.egg > PasteScript-1.1-py2.4.egg > TurboCheetah-0.9.5-py2.4.egg > > * Create the easy_install.pth, making sure the case is correct: > > import sys; sys.__plen = len(sys.path) > ./Cheetah-1.0-py2.4-win32.egg > ./CherryPy-2.2.1-py2.4.egg > ./DOMinclude-1.0-py2.4.egg > ./LightBox-2.0-py2.4.egg > ./Paste-0.9.7-py2.4.egg > ./PasteDeploy-0.9.6-py2.4.egg > ./PyProtocols-1.0a0dev_r2082-py2.4-win32.egg > ./ruledispatch-0.5a0.dev_r2115-py2.4-win32.egg > ./SQLObject-0.7.1dev_r1860-py2.4.egg > ./TurboGears-1.0.1-py2.4.egg > ./TurboJson-1.0-py2.4.egg > ./TurboKid-0.9.8-py2.4.egg > ./cElementTree-1.0.5_20051216-py2.4-win32.egg > ./configobj-4.3.2-py2.4.egg > ./elementtree-1.2.6-py2.4.egg > ./kid-0.9.3-py2.4.egg > ./simplejson-1.3-py2.4.egg > ./setuptools-0.6c5-py2.4.egg > ./FormEncode-0.6-py2.4.egg > ./PasteScript-1.1-py2.4.egg > ./TurboCheetah-0.9.5-py2.4.egg > import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; > p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p > +len(new) > > * Copy the prod.cfg into the dist dir. > > * from the dist dir try running the script > > ./python.exe start-tgpy2exe.pyc > > [EMAIL PROTECTED] [dist]> ./python.exe start-tgpy2exe.pyc > Traceback (most recent call last): > File ".\start-tgpy2exe.py", line 26, in ? > File "z:\aam\tgpy2exe\dist\lib\site-packages\TurboGears-1.0.1- > py2.4.egg\turbogears\startup.py", li > ne 300, in start_server > File "z:\aam\tgpy2exe\dist\lib\site-packages\CherryPy-2.2.1-py2.4.egg > \cherrypy\_cpserver.py", line > 72, in start > File "z:\aam\tgpy2exe\dist\lib\site-packages\CherryPy-2.2.1-py2.4.egg > \cherrypy\_cpengine.py", line > 104, in start > File "z:\aam\tgpy2exe\dist\lib\site-packages\CherryPy-2.2.1-py2.4.egg > \cherrypy\_cpserver.py", line > 76, in _start > File "z:\aam\tgpy2exe\dist\lib\site-packages\CherryPy-2.2.1-py2.4.egg > \cherrypy\_cpengine.py", line > 76, in setup > File "z:\aam\tgpy2exe\dist\lib\site-packages\CherryPy-2.2.1-py2.4.egg > \cherrypy\filters\__init__.py > ", line 66, in init > File "z:\aam\tgpy2exe\dist\lib\site-packages\CherryPy-2.2.1-py2.4.egg > \cherrypy\lib\cptools.py", li > ne 226, in attributes > File "z:\aam\tgpy2exe\dist\lib\site-packages\CherryPy-2.2.1-py2.4.egg > \cherrypy\lib\cptools.py", li > ne 215, in modules > File "z:\aam\tgpy2exe\dist\lib\site-packages\CherryPy-2.2.1-py2.4.egg > \cherrypy\filters\xmlrpcfilte > r.py", line 84, in ? > ImportError: No module named xmlrpclib > [EMAIL PROTECTED] [dist]> > > * copy the missing xmlrpclib.pyc into dist/Lib > > * Retry, hop to localhost:8080, ta-da... > > * Done > > > All the best, > > Oisin > > > > > > Oisin Mulvihill wrote: > > I'm currently tracking it down. > > > > It looks like pkg_resources isn't finding turbogears when its looking > > for packages in the dist/Lib/site-packages directory. Turbogears is > > there. If you do import turbogears you see its imported it its just the > > call to require inside turbogears startup that isn't finding itself. > Copying > > the egg file in doesn't solve the problem at the moment. More prints > > are still needed. > > > > I don't think I'll get this sorted before I go on holiday tomorrow, > maybe > > next week sometime :( > > > > All the best, > > > > Oisin > > > > > > Diego wrote: > >> I wonder if you were able to resolve the problem. > >> I'm getting the same error after using tg2exe: > >> pkg_resources.DistributionNotFound: TurboGears > >> > >> Thanks, > >> > >> Diego > >> > >> Oisin Mulvihill wrote: > >> > >>> Hello, > >>> > >>> I've asked a similar question on the py2exe mailing list > >>> (http://sourceforge.net/mailarchive/message.php?msg_id=37995269) > >>> without any response. So I'm trying a revised version here instead. > >>> > >>> Has anyone actually produced a turbogears app as an exe/standalone > >>> distro which can then be installed via inno? > >>> If so could I get a look at your setup.py / build script / magic > system > >>> you used to do this? > >>> > >>> Any help on this would be really welcomed as I've spent a week banging > >>> my head against the wall, with very little > >>> beneficial affect. > >>> > >>> What I've tried: > >>> > >>> 1. tg2exe: > >>> > >>> Appears to gather everything together without errors. However on > >>> running the app I just > >>> keep getting the error: > >>> > >>> [EMAIL PROTECTED] [dist]> ./python.exe start-tgpy2exe.pyc > >>> > >>> Traceback (most recent call last): > >>> File ".\start-tgpy2exe.py", line 5, in ? > >>> File "dist\Lib\site-packages\turbogears\__init__.py", line 8, in ? > >>> File "dist\Lib\site-packages\turbogears\widgets\__init__.py", line > 1, > >>> in ? > >>> File "dist\Lib\site-packages\turbogears\widgets\base.py", line 5, in > >>> ? > >>> File "dist\Lib\site-packages\turbogears\startup.py", line 24, in ? > >>> File "dist\Lib\site-packages\pkg_resources.py", line 585, in require > >>> File "dist\Lib\site-packages\pkg_resources.py", line 483, in resolve > >>> pkg_resources.DistributionNotFound: TurboGears > >>> [EMAIL PROTECTED] [dist]> > >>> > >>> > >>> 2. Manually specifying all modules in py2exe: > >>> > >>> I was talking to a friend and he suggested specifying the modules by > >>> hand in py2exe. I gave this a go > >>> without success. This was what I ended up with when I first tried > using > >>> py2exe. Manually specifying > >>> linecache makes no difference: > >>> > >>> [EMAIL PROTECTED] [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 > >>> [EMAIL PROTECTED] [dist]> > >>> > >>> > >>> 3. Trying non-egg installs of the dependancies: > >>> > >>> This isn't really a runner as turbogears needs setuptools and I had to > >>> do some code > >>> hacks to the dependancies. When I tried this approach I ended up back > >>> at the > >>> turbogears not found message I got using tg2exe. > >>> > >>> 4. cx_freeze: > >>> > >>> This was a last resort. I couldn't really find any examples of people > >>> trying this > >>> with turbogears. I built the exe although running it produced the > >>> error: > >>> > >>> [EMAIL PROTECTED] [tgpy2exe]> ./start-tgpy2exe.exe > >>> Traceback (most recent call last): > >>> File "c:\cx_Freeze-3.0.3\initscripts\console.py", line 27, in ? > >>> exec code in m.__dict__ > >>> File "start-tgpy2exe.py", line 5, in ? > >>> from turbogears import update_config, start_server > >>> File > >>> "C:\Python24\lib\site-packages\turbogears- > 1.0-py2.4.egg\turbogears\__init__.py", > >>> line 6, in ? > >>> > >>> from turbogears.controllers import expose, flash, validate, > >>> redirect, \ > >>> File > >>> "C:\Python24\lib\site-packages\turbogears- > 1.0-py2.4.egg\turbogears\controllers.py", > >>> line 12, > >>> in ? > >>> from turbogears import view, database, errorhandling, config > >>> File > >>> "C:\Python24\lib\site-packages\turbogears- > 1.0-py2.4.egg\turbogears\view\__init__.py", > >>> line 1, > >>> in ? > >>> from turbogears.view.base import * > >>> File > >>> "C:\Python24\lib\site-packages\turbogears- > 1.0-py2.4.egg\turbogears\view\base.py", > >>> line 17, in > >>> ? > >>> from turbogears.i18n import i18n_filter, get_locale > >>> File > >>> "C:\Python24\lib\site-packages\turbogears- > 1.0-py2.4.egg\turbogears\i18n\__init__.py", > >>> line 5, > >>> in ? > >>> from turbogears.i18n.tg_gettext import gettext, ngettext, install, > >>> is_locale_supported, \ > >>> File > >>> "C:\Python24\lib\site-packages\turbogears- > 1.0-py2.4.egg\turbogears\i18n\tg_gettext.py", > >>> line > >>> 4, in ? > >>> from turbojson.jsonify import jsonify > >>> File > >>> "C:\Python24\lib\site-packages\turbojson- > 1.0-py2.4.egg\turbojson\jsonify.py", > >>> line 6, in ? > >>> from simplejson import JSONEncoder > >>> File "C:\Python24\lib\site-packages\simplejson\__init__.py", line > 80, > >>> in ? > >>> from decoder import JSONDecoder > >>> File "C:\Python24\lib\site-packages\simplejson\decoder.py", line 19, > >>> in ? > >>> NaN, PosInf, NegInf = _floatconstants() > >>> File "C:\Python24\lib\site-packages\simplejson\decoder.py", line 13, > >>> in _floatconstants > >>> _BYTES = '7FF80000000000007FF0000000000000'.decode('hex') > >>> LookupError: unknown encoding: hex > >>> [EMAIL PROTECTED] [tgpy2exe]> > >>> > >>> I really don't know where to go from here :( > >>> > >>> > >>> 5. Forcing the customers to use linux. > >>> > >>> The ideal solution, but sadly not an option where this app will get > >>> deployed... > >>> > >>> > >>> 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 (I'm not using its python). > >>> > >>> > >>> My current monster/abomination 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 > >>> > >>> # will this fix the missing linecache? nope... > >>> import linecache > >>> > >>> # 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')), > >>> # > >>> ] > >>> > >>> opts = { > >>> "py2exe": { > >>> "compressed": 1, > >>> "optimize": 2, > >>> "ascii": 1, > >>> "bundle_files": 2, > >>> "includes": [ > >>> "kid", > >>> "linecache", > >>> "paste", > >>> "cherrypy", > >>> "configobj", > >>> "formencode", > >>> "turbogears", > >>> "turbocheetah", > >>> "turbojson", > >>> "turbokid", > >>> "cElementTree", > >>> "simplejson", > >>> "pywin", > >>> # "pyprotocols", > >>> "elementtree", > >>> "mx", > >>> "isapi", > >>> "win32com", > >>> # "ruledispatch", > >>> "setuptools", > >>> # "pastescript", > >>> # "cheetah", > >>> # "pastedeploy", > >>> # "cheetah", > >>> "elementtree", > >>> "mx.DateTime", > >>> "pkg_resources", > >>> "encodings.hex_codec", > >>> ], > >>> "packages" : [ > >>> "turbogears", > >>> ] > >>> } > >>> } > >>> > >>> > >>> > >>> # Step 4. > >>> setup( > >>> name="tgpy2exe", > >>> > >>> options = opts, > >>> > >>> version=version, > >>> > >>> console = [ > >>> WebPresenceTarget(), > >>> ], > >>> > >>> packages=find_packages(), > >>> > >>> data_files = data_files, > >>> > >>> package_data = data, > >>> ) > >>> > >>> > >>> #sys.exit(0) > >>> > >>> > >>> > >>> # 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") > >>> > >>> > >>> > >>> > >>> All the best, > >>> > >>> Oisin > >>> > >> > >> > >> > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" 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/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

