Windows question from Mac guy

Discussion in 'Python' started by Charles Hartman, Mar 18, 2005.

  1. 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. Here's the code I use for that:

    TEXTDICTIONARY = 'scandictionary.txt'
    .. . .
    try:
    f = open(TEXTDICT, 'rU')
    except IOError: # dict file has gone astray
    wildcard = "All files (*.*) | *.*"
    dlg = wx.FileDialog(None, message="Locate the scandictionary file",
    defaultDir=os.getcwd(), defaultFile="", wildcard=wildcard,
    style=wx.OPEN | wx.CHANGE_DIR)
    if dlg.ShowModal() == wx.ID_OK:
    f = open(dlg.GetPath())
    dlg.Destroy()

    When it doesn't find the file by itself (why not??), it starts looking
    down in some godawful place in Common or something, which is likely to
    baffle a user. (It baffles me, though yes I *can* navigate to the right
    place.)

    This is pretty much the same code I use when the user selects "Load
    text file," and the app goes straight to the right directory (its own
    directory), where it finds a sample text file I supply. Is os.getcwd()
    working differently in the two cases?

    Help help, I'm confused. Any help much appreciated.


    Charles Hartman
    Professor of English, Poet in Residence
    http://cherry.conncoll.edu/cohar
    http://villex.blogspot.com
     
    Charles Hartman, Mar 18, 2005
    #1
    1. Advertising

  2. Charles Hartman <> 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
     
    Thomas Heller, Mar 18, 2005
    #2
    1. Advertising

  3. On Fri, 18 Mar 2005 12:07:34 -0500, Charles Hartman
    <> declaimed the following in
    comp.lang.python:

    > isn't finding it. Here's the code I use for that:
    >

    Can't be the actual code...

    > TEXTDICTIONARY = 'scandictionary.txt'
    > . . .
    > try:
    > f = open(TEXTDICT, 'rU')


    TEXTDICT is NOT the same as TEXTDICTIONARY, so I'd have no idea
    what it is looking for... <G>


    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.netcom.com/> <
     
    Dennis Lee Bieber, Mar 19, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Waz...

    QUESTION for a MICROSOFT guy here...

    David Waz..., Jul 11, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    306
    Yan-Hong Huang[MSFT]
    Jul 15, 2003
  2. Cyber_Dragon
    Replies:
    1
    Views:
    341
  3. Replies:
    2
    Views:
    500
  4. Macon Joe Job Guy Joe Macon Job Guy

    Att: Macon Joe Job Guy Joe Macon Job Guy Macon

    Macon Joe Job Guy Joe Macon Job Guy, Oct 14, 2007, in forum: Java
    Replies:
    0
    Views:
    380
    Macon Joe Job Guy Joe Macon Job Guy
    Oct 14, 2007
  5. Replies:
    1
    Views:
    222
    Rectal Mania
    Aug 6, 2007
Loading...

Share This Page