1

I have 5 python scripts in the following folders :

  • .\Signal_Slot_Example\main.py
  • .\Signal_Slot_Example\ProgressDialog\init.py
  • .\Signal_Slot_Example\ProgressDialog\Progress.py
  • .\Signal_Slot_Example\SliderDialog\init.py
  • .\Signal_Slot_Example\SliderDialog\Slider.py

Main.py when run calls the other 2 scripts and creates a simple slid that interacts with a progress bar and when I run it in Idle it all works fine.

When I run it in the QGIS python console I get :

Traceback (most recent call last):
  File "C:\OSGEO4~1\apps\Python37\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "<string>", line 1, in <module>
  File "C:/OSGEO4~1/apps/qgis-ltr/./python\qgis\utils.py", line 672, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
ModuleNotFoundError: No module named 'SliderDialog'

Why won't it work in QGIS but runs fine in Idle ?

All the example code I have run in QGIS python console and in idle worked the same the only difference here is that I am calling classes from other .py scripts.

1 Answer 1

1

In your Signal_Slot_Example.main.py file, if you import local modules, try to add a dot before the name of the module :

import .SliderDialog
11
  • Throws an invalid syntax; the way I have the question might be confusing the "." are not actually in the file name it was my way of trying to show where the files were in the directory structure. Maybe I should have used arrows... Apr 4, 2019 at 13:48
  • Can you edit your original post to update the directories / files format ? Apr 4, 2019 at 13:55
  • I think that is better, do note that the init.py files are actually init.py is just that the __ disappear in the text block for some reason. Apr 4, 2019 at 15:04
  • try import .SliderDialog.init Apr 4, 2019 at 15:12
  • That isn't working either; from what I can tell it seems like it isn't finding the file in that path, is there a way to put in the full path? Apr 4, 2019 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.