RE: "python exe" and "py plugins"

Discussion in 'Python' started by Marc Boeren, Nov 18, 2003.

  1. Marc Boeren

    Marc Boeren Guest


    > and it works WITHOUT THE PYTHON RUNTIME INSTALLED ...
    > sure that this script can't import lib which are not in the exe ;-)


    If I remember correctly py2exe provides the python23.dll, so there's your
    runtime... meaning that you can probably import whatever library you wish in
    your plugin.
    You can probably also dynamically import your plugin instead of using
    execfile.

    Cheerio, Marc.
     
    Marc Boeren, Nov 18, 2003
    #1
    1. Advertising

  2. Marc Boeren

    marco Guest

    great ! it works with dynamic import ( __import__() )!
    it's a lot better than an execfile ...

    "Marc Boeren" <> a écrit dans le message de news:
    ...
    >
    > > and it works WITHOUT THE PYTHON RUNTIME INSTALLED ...
    > > sure that this script can't import lib which are not in the exe ;-)

    >
    > If I remember correctly py2exe provides the python23.dll, so there's your
    > runtime... meaning that you can probably import whatever library you wish

    in
    > your plugin.
    > You can probably also dynamically import your plugin instead of using
    > execfile.
    >
    > Cheerio, Marc.
    >
     
    marco, Nov 19, 2003
    #2
    1. Advertising

  3. marco wrote:
    > great ! it works with dynamic import ( __import__() )!
    > it's a lot better than an execfile ...
    >
    > "Marc Boeren" <> a écrit dans le message de news:
    > ...


    I'm a bit lost, I'm trying to do the same thing withe BitLeaf
    (www.bitbuilder.com/bitleaf).
    I put all my pulgins in a folder named "services", then when the
    application loads it looks in that folder for any subfolders that have
    __init__.py in them (packages, that's how I plan to distribute the plugins).

    That works fine in linux or uncompiled on windows, but with py2exe, it
    can't find the "services" folder.

    My question is, should I keep going down that road or is there a
    "correct" way of handling plugins in python that I'm not aware of?

    Thx
     
    Ahmad Baitalmal, Nov 19, 2003
    #3
  4. Ahmad Baitalmal <> writes:

    > marco wrote:
    >> great ! it works with dynamic import ( __import__() )!
    >> it's a lot better than an execfile ...
    >> "Marc Boeren" <> a écrit dans le message de news:
    >> ...

    >
    > I'm a bit lost, I'm trying to do the same thing withe BitLeaf
    > (www.bitbuilder.com/bitleaf).
    > I put all my pulgins in a folder named "services", then when the
    > application loads it looks in that folder for any subfolders that have
    > __init__.py in them (packages, that's how I plan to distribute the
    > plugins).
    >
    > That works fine in linux or uncompiled on windows, but with py2exe, it
    > can't find the "services" folder.


    You should be a bit more specific here - what do you mean by "it can't
    find the services folder" ?

    I can only think of two problems - first you should locate the folder in
    the file system (probably relative to the exe-file, which is
    sys.executable), and then you should add it to sys.path.
    Second, you must make sure that py2exe doesn't include this folder.

    Thomas
     
    Thomas Heller, Nov 19, 2003
    #4
  5. Thomas Heller wrote:
    >>That works fine in linux or uncompiled on windows, but with py2exe, it
    >>can't find the "services" folder.

    >
    >
    > You should be a bit more specific here - what do you mean by "it can't
    > find the services folder" ?
    >

    I figured out that's what is happening. py2exe used to package my
    "services" package because it was imported normally. But now I do a
    folder lookup to find all subfolders in my sys.executable + '/services'
    folder and
    exec("import %s" % foldername )
    each subfolder. That's why py2exe can't package those packages when its
    building.

    And I'm doing it that way because the set of plugins are not known
    ofcourse, that's why I do this dynamic discovery at runtime.


    This will work, but it feels a bit patchy to me, is there a way in
    python to say "here is the path to folder x, recursevily import all
    packages you find in there"? py, pyc, pyd also?

    Thx,
    ahmadster
     
    Ahmad Baitalmal, Nov 20, 2003
    #5
  6. Ahmad Baitalmal <> writes:

    > Thomas Heller wrote:
    >>>That works fine in linux or uncompiled on windows, but with py2exe, it
    >>>can't find the "services" folder.

    >> You should be a bit more specific here - what do you mean by "it
    >> can't
    >> find the services folder" ?
    >>

    > I figured out that's what is happening. py2exe used to package my
    > "services" package because it was imported normally. But now I do a
    > folder lookup to find all subfolders in my sys.executable +
    > '/services' folder and
    > exec("import %s" % foldername )
    > each subfolder. That's why py2exe can't package those packages when
    > its building.
    >
    > And I'm doing it that way because the set of plugins are not known
    > ofcourse, that's why I do this dynamic discovery at runtime.
    >
    >
    > This will work, but it feels a bit patchy to me, is there a way in
    > python to say "here is the path to folder x, recursevily import all
    > packages you find in there"? py, pyc, pyd also?


    No, but it's easy to do that yourself.

    Thomas
     
    Thomas Heller, Nov 20, 2003
    #6
  7. Thomas Heller <> writes:

    > Ahmad Baitalmal <> writes:
    >
    >> Thomas Heller wrote:
    >>>>That works fine in linux or uncompiled on windows, but with py2exe, it
    >>>>can't find the "services" folder.
    >>> You should be a bit more specific here - what do you mean by "it
    >>> can't
    >>> find the services folder" ?
    >>>

    >> I figured out that's what is happening. py2exe used to package my
    >> "services" package because it was imported normally. But now I do a
    >> folder lookup to find all subfolders in my sys.executable +
    >> '/services' folder and
    >> exec("import %s" % foldername )
    >> each subfolder. That's why py2exe can't package those packages when
    >> its building.
    >>
    >> And I'm doing it that way because the set of plugins are not known
    >> ofcourse, that's why I do this dynamic discovery at runtime.
    >>
    >>
    >> This will work, but it feels a bit patchy to me, is there a way in
    >> python to say "here is the path to folder x, recursevily import all
    >> packages you find in there"? py, pyc, pyd also?

    >
    > No, but it's easy to do that yourself.


    That wasn't a good answer, you already discovered that.

    But, you may want to organize your plugins somewhat differently.
    Maybe you can create a plugin package (a directory plugin, which
    contains an __init__.py file). And then you (or your users) write the
    plugins as modules contained in this directory. Or someting like that.

    It may be useful to look into sources which do something like this, PIL
    comes to mind, but there are most certainly more.

    Thomas
     
    Thomas Heller, Nov 20, 2003
    #7
  8. Thomas Heller wrote:
    > It may be useful to look into sources which do something like this, PIL
    > comes to mind, but there are most certainly more.
    >
    > Thomas


    Cool, thanks
    ahmadster
     
    Ahmad Baitalmal, Nov 20, 2003
    #8
    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. marco

    "python exe" and "py plugins"

    marco, Nov 18, 2003, in forum: Python
    Replies:
    2
    Views:
    350
    Miki Tebeka
    Nov 18, 2003
  2. Emile van Sebille

    python.exe vs pythonw.exe difference?

    Emile van Sebille, Mar 1, 2004, in forum: Python
    Replies:
    0
    Views:
    1,240
    Emile van Sebille
    Mar 1, 2004
  3. Tim Peters
    Replies:
    0
    Views:
    577
    Tim Peters
    Mar 2, 2004
  4. Chaos
    Replies:
    1
    Views:
    447
  5. whatazor

    pythonw.exe and python.exe

    whatazor, Nov 30, 2007, in forum: Python
    Replies:
    1
    Views:
    633
    Tim Roberts
    Dec 2, 2007
Loading...

Share This Page