DeepReg: import deepreg error: module 'deepreg' has no attribute 'model'

Subject of the issue

Unable to import deepreg into other python applications, using the 0.1.2 release.

>> import deepreg

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Users\zac_b\AppData\Local\NA-MIC\Slicer 4.13.0-2021-01-05\lib\Python\Lib\site-packages\deepreg\__init__.py", line 2, in <module>
    import deepreg.dataset
  File "C:\Users\zac_b\AppData\Local\NA-MIC\Slicer 4.13.0-2021-01-05\lib\Python\Lib\site-packages\deepreg\dataset\__init__.py", line 2, in <module>
    import deepreg.dataset.loader
  File "C:\Users\zac_b\AppData\Local\NA-MIC\Slicer 4.13.0-2021-01-05\lib\Python\Lib\site-packages\deepreg\dataset\loader\__init__.py", line 2, in <module>
    from deepreg.dataset.loader.grouped_loader import GroupedDataLoader
  File "C:\Users\zac_b\AppData\Local\NA-MIC\Slicer 4.13.0-2021-01-05\lib\Python\Lib\site-packages\deepreg\dataset\loader\grouped_loader.py", line 11, in <module>
    from deepreg.dataset.loader.interface import (
  File "C:\Users\zac_b\AppData\Local\NA-MIC\Slicer 4.13.0-2021-01-05\lib\Python\Lib\site-packages\deepreg\dataset\loader\interface.py", line 12, in <module>
    from deepreg.dataset.preprocess import resize_inputs
  File "C:\Users\zac_b\AppData\Local\NA-MIC\Slicer 4.13.0-2021-01-05\lib\Python\Lib\site-packages\deepreg\dataset\preprocess.py", line 11, in <module>
    from deepreg.model.layer_util import (
  File "C:\Users\zac_b\AppData\Local\NA-MIC\Slicer 4.13.0-2021-01-05\lib\Python\Lib\site-packages\deepreg\model\__init__.py", line 2, in <module>
    import deepreg.model.backbone
  File "C:\Users\zac_b\AppData\Local\NA-MIC\Slicer 4.13.0-2021-01-05\lib\Python\Lib\site-packages\deepreg\model\backbone\__init__.py", line 2, in <module>
    from deepreg.model.backbone.global_net import GlobalNet
  File "C:\Users\zac_b\AppData\Local\NA-MIC\Slicer 4.13.0-2021-01-05\lib\Python\Lib\site-packages\deepreg\model\backbone\global_net.py", line 8, in <module>
    from deepreg.model import layer, layer_util
  File "C:\Users\zac_b\AppData\Local\NA-MIC\Slicer 4.13.0-2021-01-05\lib\Python\Lib\site-packages\deepreg\model\layer.py", line 6, in <module>
    import deepreg.model.layer_util as layer_util
AttributeError: module 'deepreg' has no attribute 'model'

I suspect this has to do with the fact that layer_util is a module and not an attribute, which is why the import deepreg.model.layer_util as layer_util error is thrown.

This should be able to be resolved by replacing that code with from deepreg.model import layer_util.

If the bug is confirmed, would you be willing to submit a PR? (Help can be provided if you need assistance submitting a PR)

Yes

Your environment

  • DeepReg version 0.1.2
  • Windows 10
  • Python Version 3.6.7

Steps to reproduce

See above; call import deepreg.

Expected behaviour

deepreg should import, and then allow the user to make calls from within the API.

Actual behaviour

See above.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Without a change to the code, things can’t be solved - I’d rather find a fix that didn’t involve users needing to edit code manually

Regarding this error, can you at least try on py3.7 LOL… it’s just a random guess if py version can be the reason.

Can’t use any python other than 3.6.7 - That’s what’s built-in to 3D Slicer in the latest versions. It may increase in the future, but that’s not something we can bank on.

@YipengHu @mathpluscode - thoughts?

I installed via pip and did following

(deepreg) mathpluscode@mathpluscode-XPS-13-9300:~/Git/DeepReg$ python
Python 3.7.9 (default, Aug 31 2020, 12:42:55) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import deepreg
2021-02-01 10:36:50.961043: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
>>> 

I got no problem in Linux, btw we officially require py3.7 on Linux only. Will check more later.

Yes - no problem for me on Linux either; just a windows issue. But we need to try and find something if we want to be able to make the slicer extension work 😃