1

Consider two packages: x.y.z and x.y.w

Suppose I already have x.y.z installed via pip and I am testing x.y.w locally.

It seems that if I try to run import x.y.z it will fail with the error No module named x.y.z even though it's installed. If I switch directory, I can import it just fine, but then I won't have x.y.w. Is there any way to have both importable?

Cory Nezin
  • 1,551
  • 10
  • 22

1 Answers1

0

Adding the following to some of my __init__.py files seems to have worked:

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

(from https://docs.python.org/3/library/pkgutil.html)

However I'm not really sure why/how it worked.

Anyone care to explain?

Cory Nezin
  • 1,551
  • 10
  • 22
  • You should read more about _namespace packages_. For example you could start with [PyPA's guide on "Packaging namespace packages"](https://packaging.python.org/guides/packaging-namespace-packages/). – sinoroc Dec 02 '19 at 09:00