importing modules symbols from packages.

Richard Béneyt rbeneyt.akis at nerim.fr
Thu May 22 10:58:47 EDT 2003


Hi,

I'm in trouble with packages imports with python 2.2.1, first here is
the directories layout:

python-packages
      |
      |__ pack1
      |     |
      |     |__ __init__.py
      |     |__ module1.py
      |     |__ module2.py
      |     ...
      |__ pack2
      |     |
            |__ __init__.py
            |__ spack1
            |     |
            |     |__ __init__.py
            |     |__ modspack1.py
            |
            |__ spack2
                  |
                  |__ __init__.py
                  |__ modspack2.py


and PYTHONPATH is <some_path>/python-packages

In modspack2.py, I wrote:

      from pack1.spack1.modspack1 import aSymbol

Python answers :

      ImportError: No module named spack1.modspack1

It works if PYTHONPATH includes pack1 and pack2 directories AND I
rewrite the import in modspack2.py like this:

      from spack1.modspack1 import aSymbol

that's to say, when I remove the path first member: pack1.

Though, after reading the docs I thought that using packages (meaning
with a __init__.py in each sub-directory) only the directory containing
the packages top-level directories (here python-packages which contains
pack1 and pack2) needed to be mentioned in PYTHONPATH !?

Where can I find the whole story about packages ?

Thanks.
--
Richard Béneyt
rbeneyt.akis at nerim.fr







More information about the Python-list mailing list