Windows question from Mac guy

Thomas Heller theller at python.net
Fri Mar 18 12:28:40 EST 2005


Charles Hartman <charles.hartman at conncoll.edu> writes:

> I'm sitting here (briefly!) with a Windows machine trying to build a
> distributable for my app. I'm using py2exe and Inno Setup. (This is
> Apple-framework Python 2.3, wxPython 2.5.3.8.) Everything works!
> Except . . .
>
> My app has a data file, scandictionary.txt, that it needs to load when
> it starts up. On Mac it gets stuffed into the app bundle so it's
> hidden and there's no problem finding it. On Windows (XP), Inno Setup
> is putting it where I expected it to be, in the {app} directory along
> with my app's .exe and the various .dlls etc that Python needs. But my
> app isn't finding it.

The problem may be that the current directory is not the directory where
the exe is.  You may get the same problem in the unfrozen Python script,
depending on how you start it.
Here is code that I use, it works both for the script and the exe:

import imp, os, sys

def main_is_frozen():
    return (hasattr(sys, "frozen") or # new py2exe
            hasattr(sys, "importers") # old py2exe
            or imp.is_frozen("__main__")) # tools/freeze

def get_main_dir():
    if main_is_frozen():
        return os.path.dirname(sys.executable)
    return os.path.dirname(sys.argv[0])

Thomas



More information about the Python-list mailing list