GUI2EXE : various packaging tools and executable path

Hello,

I am using py2exe on windows, py2app on mac and custom tool (similar
to pyinstaller ) on linux.
I need to know, how you can get correct full path of app or executable
inside your scripts.

A nice article here:
http://us.pycon.org/media/2010/talkdata/PyCon2010/038/paper.html

suggests a function like this:

if CONTEXT == ('mac', 'frozen'):
    DATA = os.path.join(APP_ROOT, 'Contents','Resources') # py2app
elif CONTEXT == ('windows', 'frozen'):
    DATA = os.path.join(APP_ROOT, 'data') # py2exe
elif CONTEXT == ('linux', 'package'):
    DATA = os.path.join(sys.prefix, 'share', APP_NAME) # linux
else:
    DATA = os.path.join(...) # when run from source

I don't know what's 'APP_ROOT' here.

On various platform you can execute app using three ways:

1. Using terminal ( you are not in exe directory) by giving complete
path of application.
    for example c:/temp c:/app/app.exe (on windows)

2. Using terminal (you are in same directory where the .exe is) by
typing .exe name.

3. By mouse click (either .exe or it's shortcut) windows and linux

Considering above three situation how do I get full path of app/.exe
inside scripts?

If I know what is 'APP_ROOT' in function above then I think this will
get you correct path

if CONTEXT == ('mac', 'frozen'):
    PATH = os.path.join(APP_ROOT, 'Contents','Resources') # py2app
elif CONTEXT == ('windows', 'frozen'):
    PATH = APP_ROOT # py2exe
elif CONTEXT == ('linux', 'package'):
    PATH = sys.prefix # linux
else:
    PATH = os.path.join(...) # when run from source

any pointers?

Prashant

Hi,

Hello,

I am using py2exe on windows, py2app on mac and custom tool (similar
to pyinstaller ) on linux.
I need to know, how you can get correct full path of app or executable
inside your scripts.

A nice article here:
http://us.pycon.org/media/2010/talkdata/PyCon2010/038/paper.html

suggests a function like this:

if CONTEXT == ('mac', 'frozen'):
DATA = os.path.join(APP_ROOT, 'Contents','Resources') # py2app
elif CONTEXT == ('windows', 'frozen'):
DATA = os.path.join(APP_ROOT, 'data') # py2exe
elif CONTEXT == ('linux', 'package'):
DATA = os.path.join(sys.prefix, 'share', APP_NAME) # linux
else:
DATA = os.path.join(...) # when run from source

I don't know what's 'APP_ROOT' here.

On various platform you can execute app using three ways:

1. Using terminal ( you are not in exe directory) by giving complete
path of application.
for example c:/temp c:/app/app.exe (on windows)

2. Using terminal (you are in same directory where the .exe is) by
typing .exe name.

3. By mouse click (either .exe or it's shortcut) windows and linux

Considering above three situation how do I get full path of app/.exe
inside scripts?

If I know what is 'APP_ROOT' in function above then I think this will
get you correct path

if CONTEXT == ('mac', 'frozen'):
PATH = os.path.join(APP_ROOT, 'Contents','Resources') # py2app
elif CONTEXT == ('windows', 'frozen'):
PATH = APP_ROOT # py2exe
elif CONTEXT == ('linux', 'package'):
PATH = sys.prefix # linux
else:
PATH = os.path.join(...) # when run from source

any pointers?

I usually simply do this:

try:
    dirName = os.path.dirname(os.path.abspath(__file__))
except:
    dirName = os.path.dirname(os.path.abspath(sys.argv[0]))

To get the folder your main file is. Then you can just append the main
file name and I believe you are done. Not sure if there are catches,
but it has always worked for me.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

==> Never *EVER* use RemovalGroup for your house removal. You'll
regret it forever.
The Doomed City: Removal Group: the nightmare <==

···

On 18 February 2011 18:29, King wrote:

[ ... ]

I need to know, how you can get correct full path of app or executable
inside your scripts.

[ ... ]

I usually simply do this:

try:
     dirName = os.path.dirname(os.path.abspath(__file__))
except:
     dirName = os.path.dirname(os.path.abspath(sys.argv[0]))

To get the folder your main file is. Then you can just append the main
file name and I believe you are done. Not sure if there are catches,
but it has always worked for me.

As a point of style (avoiding bare excepts), I'd much rather see

try:
      dirName = os.path.dirname(os.path.abspath(__file__))
except StandardError:
      dirName = os.path.dirname(os.path.abspath(sys.argv[0]))

Nothing wrong with the general try/except technique, of course.

  Mel.

···

On 11-02-18 08:41 AM, Andrea Gavana wrote:

On 18 February 2011 18:29, King wrote:

Take a look at wx.StandardPaths. That will query the system APIs to give you what it considers the proper path location for various kinds of files (documents, data, configuration, etc.) Be sure to set the name of the application with wx.App.SetAppName as that value will be used for calculating some of the path names.

···

On 2/18/11 5:29 AM, King wrote:

any pointers?

--
Robin Dunn
Software Craftsman

And you want to use wx.StandardPaths because:

a) it's easier

b) there is no way to robustly find out the location of an app on all systems

c) you probably don't want the location of the exe anyway -- it's a common practie on Windows, but with multi-user sytems, etc. you can never be sure where the app resides, or whether you can write to that location, etc.

-Chris

···

On 2/18/11 9:33 AM, Robin Dunn wrote:

Take a look at wx.StandardPaths. That will query the system APIs to give
you what it considers the proper path location for various kinds of
files (documents, data, configuration, etc.) Be sure to set the name of
the application with wx.App.SetAppName as that value will be used for
calculating some of the path names.

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov