Here is my directory structure
.
|-- path1
| `-- mynms
| |-- __init__.py
| `-- app1
| |-- __init__.py
| `-- foo.py
|-- path2
| `-- mynms
| |-- __init__.py
| `-- app2
| |-- __init__.py
| `-- bar.py
`-- user.py
File contents:
$ cat user.py
#!/usr/bin/python
import sys
sys.path.append('path1')
sys.path.append('path2')
from mynms.app2.foo import foo
from mynms.app2.bar import bar
foo()
bar()
$ cat path1/mynms/__init__.py;echo ==============;cat path2/mynms/__init__.py
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
print "I am path1/mynms/__init__.py"
==============
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
print "I am path2/mynms/__init__.py"
$ cat path1/mynms/app1/foo.py; echo ============; cat path2/mynms/app2/bar.py
def foo():
print "foo!"
============
def bar():
print "bar!"
Question: When I run user.py, I get only the output of path1/__init__.py but not for path2. Is there some way to fix that?
$ ./user.py
I am path1/mynms/__init__.py -----> Why is 'I am path2/mynms/__init__.py not printed?
foo!
bar!
testcaseis misleading, let me change it.setuptoolsdoes add namespace support, but to replicate that behaviour requires extensive hacking. I can summarise whatsetuptoolsdoes at some point when I have more time, but you may as well use it directly to package up your projects and havesetuptoolsmanage the namespacing for you.