7

To organize better the code in my QGIS 3 Plugin, I tried to put all dialogs in one package called dialogs, but when I open QGIS it says ModuleNotFoundError: No module named 'dialogs'

This is the code I used to import the Dialog class in the "main" file, where there's run method (luniPlugin.py in this case)

from dialogs.select_feature_dialog import SelectFeatureDialog 

(and the same for the others dialogs)

This is the folder where the project is:

enter image description here

And, finally, this is the content of the folder "dialogs":

enter image description here

Since python compiler has not given me errors, I'm wondering if it's possible to do this "unpacking" in a QGIS Plugin or if it's simple my mistake.

1 Answer 1

10
pluginname/ top-level package __init__.py initialize the package luniPlugin.py dialogs/ sub module select_feature_dialog.py . . 

You have to specify explicitly sub module in the same package using .(dot).

Use .dialogs.select_feature_dialog (Relative import):

from .dialogs.select_feature_dialog import SelectFeatureDialog 

Or, you can use an absolute path for sub module. In this case you have to specify the package/plugin name. (Absolute import):

from pluginname.dialogs.select_feature_dialog import SelectFeatureDialog 

For more information, review Python Packages documentation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.