[Python-Dev] Relative Package Imports

James C. Ahlstrom jim@interet.com
Wed, 15 Sep 1999 15:25:24 -0400

Jim Fulton wrote:
> In this context, consider the following concrete, though fictional
> example.
> ............

The classical solution would be to add "Shared" to sys.path.  But
how to do this?  And what if another installation changes it?

> I'd be curious to hear how folks would solve this problem.

1) Ship a custom binary interpreter with critical modules frozen in,
and which sets a custom sys.path before anything else happens.  So
you are not dependent at all on PYTHONPATH.  Currently this works.

2) Add a new command line option which sets sys.path and always use
it to start your app.  It lists only critical zope directories so
zope has its own private name space.

3) Add your own import hooks using imputil.py and boot it as
in (1).  Better if it were part of Python.

4) Use a new Python.pyl file which has seeking from the end and
thus allows concattenation of multiple *.pyl.  Each package is
a foo.pyl, bar.pyl, and to distribute an app, you concatenate
packages.  The implied PYTHONPATH in each *.pyl file is "."
except perhaps for the Python lib which is "Lib".  Boot it as
in (3).

> Personally, I'd like the problem to go away. :)

I have the same problem, so me too.

> I'd like the Python
> import rules to change to make this solvable without import hooks or
> path hacking.  I can think of two ways to approach this:
>   - Relative parent imports:
>       import __.kjParsing.kjParser

OK by me, but doesn't solve the Grand Problem.
>   - Gradually less local searches.

I am currently bewildered by Python's import mechanism, and
this may push me into brain damage.  Well, *more* brain damage.

Jim Ahlstrom