Manipulating sys.path

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas

    Manipulating sys.path

    Hi all,

    I want to manipulate sys.path outside of PYTHONPATH (environment) and
    sys.path.append () (programmatical ly).

    A bit of background:
    We're maintaining a small application that includes a couple of Python
    scripts. Over time, a decent amount of code has been forked into
    modules, so the overall file system layout of our kit looks like this:

    tool/
    bin/
    prog1.py
    prog2.py
    ...
    lib/
    pack1/
    mod1.py
    mod2.py
    ...

    The issue I have is that I want to add the 'lib' directory to the module
    search path so that our programs prog1.py, prog2.py,... can find the
    modules pack1.mod1, pack1.mod2, ... But I want to keep this out of the
    program's source code which rules out statements like
    'sys.path.inser t(0, "../lib")'. We also want to be minimal-invasive for
    the hosting environment, so no copying of 'lib' into the standard Python
    lib directories (like /usr/local/lib/python2.5/site-packages etc.), nor
    forcing the user to change his PYTHONPATH shell environment. It should
    be solved locally in our kit's directory tree.

    I was thinking about putting code into a 'bin/__init__.py' file but
    that's only working for modules and not for executable scripts, right?!
    Then I came across the '.pth' files, but unfortunately they only seem to
    work in some standard paths (like the before mentioned
    /usr/local/lib/python2.5/site-packages), and not in the script directory
    (like 'bin' in my case) which is automatically added to sys.path.

    Can anybody think of something that could be of help here?

    Thanks,
    Thomas
Working...