Newbie packages Q

Alex Martelli aleax at mac.com
Sun Oct 7 19:24:39 EDT 2007


MarkyMarc <marcsgbrevkonto at gmail.com> wrote:
   ...
> > As long as '/python' comes in the list before any other directory that
> > might interfere (by dint of having a Test.py or Test/__init__.py), and
> > in particular in the non-pathological case where there are no such
> > possible interferences, my assertion here quoted still holds.
> >
> > If you're having problems in this case, run with python -v to get
> > information about all that's being imported, print sys.path and
> > sys.modules just before the import statement that you think is failing,
> > and copy and paste all the output here, incuding the traceback from said
> > failing import.
> >
> > Alex
> 
> OK thank you, with some help from the -v option and debugging I found
> a test package in some package. I now renamed it and load it with
> sys.path.append.
> And now the btest.py works.

Good.

> BUT does this mean I have to set the path too the package in every
> __init__.py class?
> Or have do I tell a subpackage that it is part of a big package ?

The package directory (the one containing __init__.py) must be on some
directory in sys.path, just like a plain something.py module would have
to be in order to be importable.  How you arrange for this is up to you
(I normally install all add-ons in the site-packages directory of my
Python installation: that's what Python's distutils do by default, ).
As for conflict in names (of modules and/or packages), they're of course
best avoided than worked-around; not naming any module test.py, nor any
package (directory containing an __init__.py) Test, is a good start.


Alex



More information about the Python-list mailing list