Extension development: Right way to import a module with subdirectories

I am trying to import a rather complex module into my frontend extension: nfcpy

Problem is: I import the whole directory via “import nfc”, unfortunately all submodules of nfc will not be found, starting with nfc.tag which is in __init__.py of "nfc/clf"
What’s going wrong? Why are the parent modules not found?

ERROR    Extension nfcread failed during setup, this might have left the registry in a bad state.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/mopidy/__main__.py", line 145, in main
    extension.setup(registry)
  File "/home/pi/mopidy-nfcread/mopidy_nfcread/__init__.py", line 30, in setup
    from .frontend import NFCread
  File "/home/pi/mopidy-nfcread/mopidy_nfcread/frontend.py", line 5, in <module>
    from readnfctag import ReadTag
  File "/home/pi/mopidy-nfcread/mopidy_nfcread/readnfctag.py", line 5, in <module>
    import nfc
  File "/home/pi/mopidy-nfcread/mopidy_nfcread/nfc/__init__.py", line 28, in <module>
    from clf import ContactlessFrontend
  File "/home/pi/mopidy-nfcread/mopidy_nfcread/nfc/clf/__init__.py", line 32, in <module>
    import nfc.tag
ImportError: No module named nfc.tag

It’s working flawlessly if I run it on it’s own (not as an extension).


Directory structure

|--- frontend.py (imports readnfc.py)
|--- readnfc.py (imports nfc)
|
|--- nfc
|    |--- __init__.py
|    |--- clf (imports nfc.tag) <–– fails here
|    |    |--- _init__.py
|    |    |--- etc.
|    |--- tag
|    |    |--- __init__.py
|    |    |--- etc.
|    |--- etc.

TL;DR

In my extension I want to import a module with sub directories which require each other at certain points. As soon as one file requires a sibling via the parent it will not be found. However the same code is working if it’s not an extension.

Any idea what I am doing wrong? Are there any special import requirements when using extensions? I’d rather not want to change “nfc” module as there a a lot, A LOT of files.