I am trying to freeze an application on linux using pyinstaller 1.3.
The application uses resource files and I am running into trouble.

The broken code is a subroutine getResourceDir
that returns the path to a resource directory (code appended).

I test for sys.frozen == 1 so I know not to use module __file__
attributes (since it's dead wrong).
I then look at sys.executable, which is "disttui/tui".
I try to expand that to an absolute path using:
   os.path.abspath(os.path.dirname(sys.executable))
but it returns the wrong answer, presumably because
the current working directory was altered at some point.

I realize I can rewrite my application to expand sys.executable
immediately and then cache that somewhere until I need it,
but I think that involve major rewriting or the risky assumption
(such as assuming that the module containing getResourceDir will always
be imported at startup).

The code works fine for py2app and py2exe, relying on the
useful attribute that __file__ is correct for modules.
Also, sys.executable is absolute for py2app (I don't know about py2exe).
pyinstaller has neither and I'm stumped.

Any suggestions?

Or...any idea how hard it would be to modify pyinstaller to provide 
an absolute sys.executable or usable module __file__ attributes? I've 
not looked at the source code yet.

-- Russell

P.S. here's the code:

def getResourceDir(pkg, *args):
    sysFrozen = getattr(sys, "frozen", None)
    if sysFrozen == 1:
       # handle pyinstaller; pkg.__file__ is dead wrong
       pkgRoot = os.path.abspath(os.path.dirname(sys.executable))
    else:
       pkgRoot = os.path.dirname(os.path.dirname(pkg.__file__))
       if pkgRoot.lower().endswith(".zip"):
          # handle py2app and py2exe
          pkgRoot = os.path.dirname(pkgRoot)
    return os.path.join(pkgRoot, pkg.__name__, *args)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"PyInstaller" 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/PyInstaller?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to