How to create namespace packages in Python?

心不动则不痛 提交于 2019-12-04 16:33:14

Namespace packages can be built with distribute. The trick is then to add the following line to the parameter of setup:

setup(
  # ...
  namespace_packages  = ["root"]
)

The rest of the example in the question is correct.

I just tried your example, but it seems to work like you want it to:

    >>> from root.sub.actualcode import foo
    >>> foo()
    Bar!

I ran the Python interpreter from the directory containing the root folder. I created the empty __init__.py files and my actualcode.py looks like this:

    #!/bin/python3

    def foo():
        print("Bar!")

The difference is that my __init__.py files are empty.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!