Absolute Imports and PYTHONPATH

John Roth newsgroups at jhrothjr.com
Wed May 5 19:59:59 EDT 2004


"Richard Cooper" <python-list at richardcooper.net> wrote in message
news:mailman.288.1083793726.25742.python-list at python.org...
> I can't believe I've just been bitten by this again!
>
> I'm part of a team writing an application in python. We have an fairly
> extensive package structure and like sensible pythoneers we use
> absolute imports throughout. The top level of our package is in
> PYTHONPATH so that all the absolute imports can work.
>
> This is all fine and dandy until I start playing with two different
> versions of the code (working on 2 CVS branches for example). Whenever
> I do this I inevitably forget to change PYTHONPATH at some point and
> waste an hour or so debugging a problem that occurred because the
> __main__ module from one tree is now importing from the other. This has
> happened to me a few times now and is really irritating.
>
> Am I missing an obvious non-hacktastic way to avoid this problem?
>
> If not would it be possible to fix this problem in a future python? I'm
> thinking something along the lines of:
>
> When a module is imported its import search path includes everything it
> does now PLUS the directory that is the top of the module's enclosing
> package structure. That way you wouldn't have to add entries to
> PYTHONPATH for packages that only import from themselves (and stdlib
> and site-packages). Possible? Sensible? What do you think?

As far as I'm concerned, the whole notion of Pythonpath is seriously
broken, but I'm not about to suggest replacing it given the discussion
around PEP 328. Redesigning the whole import mechanism is something
that will have to wait for the ever receeding 3.0

What I do is I have a separate command prompt (I'm on Windows)
for each different Pythonpath I need to work with, and it sets the
correct path for the rest of the work.
>
> Regards,
>
> Rich
>
>





More information about the Python-list mailing list