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

Created on 1 Feb 2021  路  16Comments  路  Source: DeepRegNet/DeepReg

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.

bug priority

All 16 comments

@YipengHu @mathpluscode - thoughts?

@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.

@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 :)

Actually, I wonder if we can do CI on win/mac os, https://github.com/actions/virtual-environments.

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.

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.

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.

I see! Then maybe we need two issues:

  • support windows/mac (Mac should be ok)
  • support py3.6, 3.8

I'm closing this before raising another ticket reporting for a specific bug #664.

@YipengHu this issue is not related to #664?

@zacbaum see if you would like to close this in favour of adding a doc to avoid others to go through what you experienced?

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

@zacbaum is this still blocking you?

@zacbaum is this still blocking you?

SInce nothing has been changed... I'd suspect yes. Right now, this requires a change to the source code after pip installing in slicer (messy and not good practice). I haven't had a chance to try this workaround in a Linux system to check if tests pass with it.

@zacbaum is this still blocking you?

SInce nothing has been changed... I'd suspect yes. Right now, this requires a change to the source code after pip installing in slicer (messy and not good practice). I haven't had a chance to try this workaround in a Linux system to check if tests pass with it.

Sure, I guess the solution should be supporting multiple python versions.

It was due to

https://github.com/DeepRegNet/DeepReg/blob/main/deepreg/model/layer.py#L9

where is should be from deepreg.model import layer_util

closing this as @zacbaum confirmed that the bug was fixed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NMontanaBrown picture NMontanaBrown  路  5Comments

mathpluscode picture mathpluscode  路  3Comments

NMontanaBrown picture NMontanaBrown  路  5Comments

zacbaum picture zacbaum  路  3Comments

NMontanaBrown picture NMontanaBrown  路  5Comments