Search code examples
pythonpippackagingpython-packagingpython-importlib

Python packaging - how to make sub-modules importable from higher-level module?


The following works in my python package:

import Top.Lower

However, the following does not work:

import Top
print(Top.Lower)

I'm using packages = find: in my setup.cfg as well as:

[options.package_data]
Top =
    **/*.py

Any idea how to get the import Top syntax to work?


Solution

  • Tell it to import everything from Top:

    from Top import *  # Asterisk means everything.
    
    print(Top.Lower)  # Should work.
    print(Top.OtherLower)  # Should also work.