Re: Help with pythonpath
- From: mg <mg.mailing-list@xxxxxxxxxxx>
- Date: Mon, 06 Jun 2005 09:01:43 +0200
Tim Roberts wrote:
Observer <observer@xxxxxxxxxxxxxxxx> wrote:If I remember, I think you need to add an __init__.py file just in your directories src & src2.
Hi, im a newbie both to python and this list. I hope someone can help me whith this:
I have a directory structure like this: . |-- src | `-- pkg | |-- __init__.py | |-- main.py | `-- spkg1 | |-- __init__.py | `-- config.py `-- src2 `-- pkg |-- __init__.py `-- spkg2 |-- __init__.py `-- config2.py
and main.py is a python script that contains this imports:
from pkg.spkg1 import config from pkg.spkg2 import config2
executed in linux whith this:
env PYTHONPATH=src:src2 src/pkg/main.py Traceback (most recent call last): File "src/pkg/main.py", line 4, in ? from pkg.spkg2 import config2 ImportError: No module named spkg2
changing the order of the python path only inverts the problem, is there
any way to solve this without changing the directory structure?
Nope. When Python goes to look for a package called "pkg", it starts at
the beginning of PYTHONPATH and stops as soon as it finds one. You either
need to use different names for the two packages (pkg1, pkg2), or use a
symbolic link to link spkg2 into the src directory.
Moreover, you can add the path of src and src2 to the variable sys.path at the beginning of your main script (in that case, it not necessary to define PYTHONPATH)
I hope I help you Mathieu .
- References:
- Help with pythonpath
- From: Observer
- Re: Help with pythonpath
- From: Tim Roberts
- Help with pythonpath
- Prev by Date: Re: Socket Speed
- Next by Date: Re:
- Previous by thread: Re: Help with pythonpath
- Next by thread: help with extending python
- Index(es):
Loading