I am unable to get the following things to work simultaneously in Python2.7:
import submodules from a local package
import submodules from the package when it is on the PYTHONPATH
I have set up the sample directory structure as in the python docs for packages
cd tmp
mkdir sound
mkdir sound/formats
mkdir sound/effects
mkdir sound/filters
cd sound
touch __init__.py
cp !$ formats/
cp __init__.py formats/
cp __init__.py effects/
cp __init__.py filters/
echo "def echofilter(): return(1) " > effects/echo.py
cd ../..
So, I end up with:
$ ls tmp/sound
effects/ filters/ formats/ __init__.py
If I make the package local, as it would be if it were acting as a git submodule, for instance, ie by cd tmp, the following is successful:
$ python
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
>>> from sound.effects import echo
>>>
Yet if I am located somewhere else (cd ..), and I put the package on my PYTHONPATH, I cannot import as in the docs:
[~/tmp]$ cd ..
[~]$ python
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
>>> import sys
>>> sys.path.append('/home/meuser/tmp/sound')
>>> from sound.effects import echo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sound.effects
>>> sys.path.append('/home/meuser/tmp/sound/effects')
>>> from sound.effects import echo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sound.effects
So how am I supposed to arrange things?