Hi Daniel,
     I am using Apache and an application server written in python. A CGI request from apache is handled by the application server (getting data from the database or doing some simulation etc). The "unknowns" in certain format with user requests on a web page will be substituted by the application server and the web page will be sent back the end users after substitution.
    After I searched the web and found a solution for now (maybe not good one). Here is what I did:   first py2exe the python CGI script and second modify that CGIHTTPServer.py in python24\Lib as follow:  
 
# Comment the original code and add  cmdline = "%s -u %s" % ('distpython', cmdline)
 
if self.is_python(scriptfile):
                #interp = sys.executable
                #if interp.lower().endswith("w.exe"):
                #    # On Windows, use python.exe, not pythonw.exe
                #    interp = interp[:-5] + interp[-4:]
                #cmdline = "%s -u %s" % (interp, cmdline)
               cmdline = "%s -u %s" % ('distpython', cmdline)

Now my python CGI in exe is working. I will try mod_python for apache and see if it is ok with my server.
 
Thank you very much.
 
Ouyang
 
On 8/10/07, Daniel Pryden <daniel@pryden.net> wrote:
Maybe I'm confused, but it sounds like you're trying to distribute a set
of HTML files along with a set of CGI executables, where in this case
the CGI executables just happen to be written in Python and compiled
with py2exe.  But where is the web server in this case?  Is it in Python
or are you using Apache?

If you're using Apache, you're probably a lot better off using
mod_python than using py2exe-compiled CGIs, since with the CGI method
you get the overhead of the interpreter bootstrap (and the py2exe
bootstrap) on every web request.  If you're not using Apache, then why
bother with CGI?  Why not just write an HTTP handler in Python and
dispatch all your web requests from there -- or else use a framework for
this, of which there are plenty (CherryPy and Twisted come immediately
to mind).

There are also various other hybrid approaches that could be used here
-- for example, many application servers work by servicing HTTP requests
on a higher-numbered port and then setting up Apache to forward requests
that match a certain pattern to that port.  This actually gives your
users a lot of flexibility as to how they would like the application set up.

It seems like you are going about this the wrong way -- I doubt py2exe
is really what you want to be using to solve your problem.

- Daniel.

zhihua ouyang wrote:
> Larry,
>   Thanks for your suggestions. My web application works with current
> apache configuration. After I wrap it up with pyexe, the server part
> (main_sps.exe) is working, but python cgi part are not working. If I
> login via IE, the erro msg is:
> """ Internal Server Error
>
> The server encountered an internal error or misconfiguration and was
> unable to complete your request. .... """
>
> This may be caused by the first line in my python cgi scripts:  #!
> c:/python24/python.exe since there is no where to find the python.exe
> after py2exe.
>
> Here is what I did:
> 1. I put the setup.py in c:/xbop_sinopec/bin/SERIAL_PORT and "python
> setup.py py2exe" from there
> 2. The following is my setup.py . I am trying to use scripts = [.....] to
> get my pythong CGI work but got the above error.
>
> Any ideas?
>
> Ouyang
>
> #################################################
>
> from distutils.core import setup
> import py2exe
> import sys
>
> from distutils.filelist import findall
> import os
> import matplotlib
> excludes = ["pywin", " pywin.debugger", "pywin.debugger.dbgcon",
>             "pywin.dialogs", " pywin.dialogs.list",'_gtkagg', '_tkagg']
> #, "win32com.client"]
>
> includes=['aifc','anydbm','asynchat','asyncore','atexit','audiodev','base64','BaseHTTPServer','Bastion','bdb',
> 'binhex','bisect','bsddb','bsddb.*','calendar','cgi','CGIHTTPServer','cgitb','chunk','cmd',
>
> 'code','codecs','codeop','colorsys','commands','compileall','compiler','compiler.*','ConfigParser','Cookie',
> 'cookielib','copy','copy_reg','csv','curses','curses.*','dbhash','decimal','difflib','dircache',
>
> 'dis','distutils','distutils.*','doctest','DocXMLRPCServer','dumbdbm','dummy_thread','dummy_threading','email','email.*',
> 'encodings','encodings.*','filecmp','fileinput','fnmatch','formatter','fpformat','ftplib','getopt','getpass',
>
> 'gettext','glob','gopherlib','gzip','heapq','hmac','hotshot','hotshot.*','htmlentitydefs','htmllib',
> 'HTMLParser','httplib','idlelib','idlelib.*','ihooks','imaplib','imghdr','imputil','inspect','keyword',
>
> 'linecache','locale','logging','logging.*','macpath','macurl2path',
> 'mailbox','mailcap','markupbase','mhlib','mimetools','mimetypes','MimeWriter','mimify','modulefinder','multifile',
>
> 'mutex','netrc','new','nntplib','ntpath','nturl2path','opcode','optparse','os','os2emxpath',
> 'pdb','pickle','pickletools','pipes','pkgutil','platform','popen2','poplib','posixfile','posixpath',
>
> 'pprint','profile','pstats','pty','pyclbr','pydoc','py_compile','Queue','quopri','random',
> 're','reconvert','regex_syntax','regsub','repr','rexec','rfc822','rlcompleter','robotparser','sched',
>
> 'sets','sgmllib','shelve','shlex','shutil','SimpleHTTPServer','SimpleXMLRPCServer','site',
> 'smtpd','smtplib','sndhdr','socket','SocketServer','sre','sre_compile','sre_constants','sre_parse',
>
> 'stat','statcache','statvfs','string','StringIO','stringold','stringprep','subprocess','sunau','sunaudio',
> 'symbol','symtable','tabnanny','tarfile','telnetlib','tempfile','textwrap','this',
>
> 'threading','timeit','toaiff','token','tokenize','trace','traceback','tty','types','tzparse',
> 'unittest','urllib','urllib2','urlparse','user','UserDict','UserList','UserString','uu','warnings',
>
> 'wave','weakref','webbrowser','whichdb','whrandom','xdrlib','xml','xml.*','xmllib','xmlrpclib',
> 'zipfile','_LWPCookieJar','_MozillaCookieJar','_strptime','_threading_local','__future__']
>
>
> packages=['mx','pyExcelerator','ctypes','serial','matplotlib','numpy','pytz']
>
> options = {
>     "ascii": 1, # to make a smaller executable, don't include the encodings
>     "compressed": 0, # compress the library archive
>     "skip_archive": 1,
>     "excludes": excludes, # COM stuff we don't want
>     'dll_excludes':
> ['libgdk-win32-2.0-0.dll','libgobject-2.0-0.dll','libgdk_pixbuf-2.0-0.dll','wxmsw26uh_vc.dll',' python22.dll','tk83.dll','tcl83.dll'],
>
>     "includes": includes,
>     "packages": packages,
>     "dist_dir": "Python24",
>     }
>
> setup(
>       name='xbop',
>       version='1.0',
>       description='wisco point monitoring',
>
>     console=['main_sps.py'],
>     options = {"py2exe": options},
>     scripts = ['c:\\xbop_sinopec\\scripts\\wisco\\mAcquisition.py',
> 'c:\\xbop_sinopec\\scripts\\wisco\\mAcq_system.py',
> 'c:\\xbop_sinopec\\scripts\\wisco\\mPoint_check.py',
> 'c:\\xbop_sinopec\\scripts\\wisco\\mRpt_data_record_query.py',
> 'c:\\xbop_sinopec\\scripts\\wisco\\mRpt_dia_plan_query.py',
> 'c:\\xbop_sinopec\\scripts\\wisco\\mRpt_fault_overhaul_query.py',
> 'c:\\xbop_sinopec\\bop-cgi\\xbop.py' ],
>     data_files=[matplotlib.get_py2exe_datafiles()],
>     )
> ################################################
>
>
>
>
>
>
>
>
>
> On 8/7/07, *Larry Bates* <larry.bates@websafe.com
> <mailto:larry.bates@websafe.com >> wrote:
>
>     zhihua ouyang wrote:
>     >  Hi,
>     >    I have tried to use py2exe to wrap my web application associated
>     with
>     >  my python application server for end users but failed.
>     >  I want to use py2exe and INNO SETUP to wrap everything so that a user
>     >  does not have to install python.
>     >  My code is organized as follows:
>     >    # __init__.py in every subdirectory for python codes
>     >    # matplotlib, pyExcerator,numpy etc are used in the application
>     >    c:/gdas
>     >                bin/serial_port/main_sps.py   #script to start the
>     >  application server
>     >                bin/serial_port/*.py               #be imported by
>     >  main_sps.py
>     >                bin/*.py                               #many other
>     modules
>     >                db/*.py                 &nbs p;              #more
>     py files for
>     >  the application code
>     >
>     >                htdocs/                                # for web pages
>     >                htdocs/jslib/*.js                     # javascript libs
>     >                htdocs/xxxx/*.html          &nbs p;      # html web
>     pages
>     >                htdocs/graphics/*.jpg            # images for web pages
>     >                scripts/                                # python files
>     >  (first line #!c:/python24/python.exe)
>     >                scripts/xxxx/*.py                    # associated
>     with the
>     >  html pages.
>     >                .....
>     >    The python applicatin server start from
>     >  c:/gdas/bin/serial_port/main_sps.py with multithreading. A user can
>     >  login the system via the html page in c:/gdas/htdocs/xxxx/*.html.
>     >     I really appreciate your suggestions. A py2exe setup example would
>     >  be very helpful. Thanks a lot.
>     >
>     >  Ouyang
>     >
>     >
>
>     What isn't working?  There are examples here:
>
>     http://www.py2exe.org/index.cgi/Tutorial
>     http://wiki.python.org/moin/Py2Exe
>
>     -Larry
>
>
>
>
>     -------------------------------------------------------------------------
>
>     This SF.net email is sponsored by: Splunk Inc.
>     Still grepping through log files to find problems?  Stop.
>     Now Search log events and configuration files using AJAX and a browser.
>     Download your FREE copy of Splunk now >>   http://get.splunk.com/
>     _______________________________________________
>     Py2exe-users mailing list
>     Py2exe-users@lists.sourceforge.net
>     <mailto:Py2exe-users@lists.sourceforge.net>
>     https://lists.sourceforge.net/lists/listinfo/py2exe-users
>     <https://lists.sourceforge.net/lists/listinfo/py2exe-users>
>
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Py2exe-users mailing list
> Py2exe-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/py2exe-users


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Py2exe-users mailing list
Py2exe-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/py2exe-users