executable path finding

Discussion in 'Python' started by koranthala, Aug 31, 2009.

  1. koranthala

    koranthala Guest

    Hi,
    I am creating a python application using py2exe. I am facing a
    problem which I am not sure how to solve.
    The application contains many other files associated with it -
    like icons, config files etc. The executable can be in any directory.
    If the user creates a shortcut to the executable to run in desktop,
    the program fails - saying that the icon image cannot be found. But I
    can run the application properly, if I run it from application
    directory - where all the other icons, config files etc are kept.
    How is such issues usually solved? I do not want to hardcode the
    paths of icons and store the icons in those paths. I guess, we can
    change the directory to the application directory before running the
    application. (in __init__.py ???) But how do we find the current
    directory in that case? I am completely at sea in solving this.
    This looks to be a very common issue. How is this usually solved?
     
    koranthala, Aug 31, 2009
    #1
    1. Advertising

  2. koranthala wrote:

    > Hi,
    > I am creating a python application using py2exe. I am facing a
    > problem which I am not sure how to solve.
    > The application contains many other files associated with it -
    > like icons, config files etc. The executable can be in any directory.
    > If the user creates a shortcut to the executable to run in desktop,
    > the program fails - saying that the icon image cannot be found. But I
    > can run the application properly, if I run it from application
    > directory - where all the other icons, config files etc are kept.
    > How is such issues usually solved? I do not want to hardcode the
    > paths of icons and store the icons in those paths. I guess, we can
    > change the directory to the application directory before running the
    > application. (in __init__.py ???) But how do we find the current
    > directory in that case? I am completely at sea in solving this.
    > This looks to be a very common issue. How is this usually solved?


    You can get the location of a module via

    module.__file__

    This can be used to find a file relative to e.g. the toplevel module/package
    of your application.

    The pkg_resources-module of setuptools encapsulates that even into a stream
    and file-name api.

    Diez
     
    Diez B. Roggisch, Aug 31, 2009
    #2
    1. Advertising

  3. koranthala

    koranthala Guest

    On Aug 31, 9:07 pm, "Diez B. Roggisch" <> wrote:
    > koranthala wrote:
    > > Hi,
    > >     I am creating a python application using py2exe. I am facing a
    > > problem which I am not sure how to solve.
    > >     The application contains many other files associated with it -
    > > like icons, config files etc. The executable can be in any directory.
    > > If the user creates a shortcut to the executable to run in desktop,
    > > the program fails - saying that the icon image cannot be found. But I
    > > can run the application properly, if I run it from application
    > > directory - where all the other icons, config files etc are kept.
    > >     How is such issues usually solved? I do not want to hardcode the
    > > paths of icons and store the icons in those paths. I guess, we can
    > > change the directory to the application directory before running the
    > > application. (in __init__.py ???) But how do we find the current
    > > directory in that case? I am completely at sea in solving this.
    > >     This looks to be a very common issue. How is this usually solved?

    >
    > You can get the location of a module via
    >
    >  module.__file__
    >
    > This can be used to find a file relative to e.g. the toplevel module/package
    > of your application.
    >
    > The pkg_resources-module of setuptools encapsulates that even into a stream
    > and file-name api.
    >
    > Diez


    Thank you Diez. It was what I was looking for.
     
    koranthala, Aug 31, 2009
    #3
  4. koranthala

    ryles Guest

    On Aug 31, 12:37 pm, koranthala <> wrote:
    > On Aug 31, 9:07 pm, "Diez B. Roggisch" <> wrote:
    >
    >
    >
    > > koranthala wrote:
    > > > Hi,
    > > >     I am creating a python application using py2exe. I am facing a
    > > > problem which I am not sure how to solve.
    > > >     The application contains many other files associated with it -
    > > > like icons, config files etc. The executable can be in any directory.
    > > > If the user creates a shortcut to the executable to run in desktop,
    > > > the program fails - saying that the icon image cannot be found. But I
    > > > can run the application properly, if I run it from application
    > > > directory - where all the other icons, config files etc are kept.
    > > >     How is such issues usually solved? I do not want to hardcode the
    > > > paths of icons and store the icons in those paths. I guess, we can
    > > > change the directory to the application directory before running the
    > > > application. (in __init__.py ???) But how do we find the current
    > > > directory in that case? I am completely at sea in solving this.
    > > >     This looks to be a very common issue. How is this usually solved?

    >
    > > You can get the location of a module via

    >
    > >  module.__file__

    >
    > > This can be used to find a file relative to e.g. the toplevel module/package
    > > of your application.

    >
    > > The pkg_resources-module of setuptools encapsulates that even into a stream
    > > and file-name api.

    >
    > > Diez

    >
    > Thank you Diez. It was what I was looking for.


    Also see:

    http://docs.python.org/library/pkgutil.html
     
    ryles, Sep 1, 2009
    #4
    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. Josephine Schafer
    Replies:
    1
    Views:
    3,633
    Philip Morley
    Jul 21, 2003
  2. Replies:
    15
    Views:
    511
    Dave Thompson
    Aug 21, 2006
  3. pratap
    Replies:
    20
    Views:
    792
    Flash Gordon
    Mar 7, 2007
  4. Jason Cavett
    Replies:
    8
    Views:
    660
    Sanjay
    May 16, 2007
  5. Michael Hoffman

    Finding the full path of an executable

    Michael Hoffman, Jan 16, 2009, in forum: Python
    Replies:
    2
    Views:
    432
    Gabriel Genellina
    Jan 17, 2009
Loading...

Share This Page