How to handle sys.path in bigger projects?

Georg Lohrer GeorgLohrer at gmx.de
Fri Oct 12 07:42:03 EDT 2001


On 12 Oct 2001 11:52:30 +0200, Martin von Loewis
<loewis at informatik.hu-berlin.de> wrote:

>Georg Lohrer <GeorgLohrer at gmx.de> writes:
>
>> What are your ways of handling?
>
>If you are relying on a lot of third-party packages, I'd require that
>those packages get properly installed, ie. into site-packages or
>site-python. Then you only need to find your own code.

I'm only bothered by my own code :-)

>
>If that grows in size, organizing it into multiple packages seems to
>be appropriate. I then see no problem in keeping all these packages in
>a single directory.

Ok. Let's have a look on it:

1) actual dir contains directory: "myproject" with its __init__.py
importing myproject.foo1 and myproject.foo2
2) two sub-packages (directories) called "foo1" and "foo2" with each
containing a __init__.py are within "myproject"
3) foo1 contains foo1foo.py; foo2 contains foo2foo.py
4) foo2foo.py has a intra-package reference to foo1foo.py: 
import myproject.foo1.foo1foo

Running from parent-dir of "myproject"

~user> python
>>> from myproject.foo1 import foo1foo
>>>

runs successfully. But if I want to test the foo1foo.py module itself,
following the path to myproject/foo1:

~user/myproject/foo1> python
>>> import foo1foo
*** ImportError: No module named myproject.foo2

So, the only way that seems to work is to start debugging from most
upper directory, if there are intra-package references? Is that
correct? Or how do you handle this?

Ciao, Georg




More information about the Python-list mailing list