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
-~----------~----~----~----~------~----~------~--~---

Reply via email to