I have modules at two different locations
e.g
Location1
|- com
|-__init__.py
|-foo1
|-__init__.py
|-bar1.py
Location2
|- com
|-__init__.py
|-foo2
|-__init__.py
|-bar2.py
The two locations are in the PYTHONPATH, in the above order. When I try to import com.foo2.bar2, I get the following error:
Traceback (most recent call last): File "", line 1, in ImportError: No module named foo2
If I change the top-level package name to com2 (i.e location2/com2/foo2/bar2.py), then the import statement succeeds.
I think I am doing something incorrect, could someone please help?
Thanks.
What you want is called namespace packages in Python. One way to do them with the standard library is to use pkgutil; another way is to use the third-party module pkg_resources provided by the distribute or setuptools projects.
Support for namespace packages will be improved in the standard library and interpreter with PEP 382.