1

While doing a first-time attempt to craft a simple plugin, I ran into the above error.

I am using QGIS 2.6.0 for windows, the QT Designer that comes with that package, and the plugin builder plugin 2.0.3

I created the simplest of UI's almost identical to that found at: http://anitagraser.com/2014/04/26/getting-started-writing-qgis-2-x-plugins/

Compiled the UI and resource file, as instructed, and then placed the folder within the bounds of the QGIS folders.

Opening QGIS, then the plugin manager, I saw my plugin, and attempted to click it, and the DLG box reported this error [full stack, below "==="):

File "C:/PROGRA~1/QGISBR~1/apps/qgis/./python/plugins\TestPlugin\testplugindialog.py", line 24, in from ui_testplugin import Ui_TestPlugin ImportError: cannot import name Ui_TestPlugin

I infer a circular import, or other problem, but that file referred to is created by the Plugin Builder.

Can anyone provide any hints as to why this error is popping up? I am at wits end. Thanks

================ Couldn't load plugin TestPlugin due an error when calling its classFactory() method

Traceback (most recent call last):
  File "C:/PROGRA~1/QGISBR~1/apps/qgis/./python\qgis\utils.py", line 208, in startPlugin
    plugins[packageName] = package.classFactory(iface)
  File "C:/PROGRA~1/QGISBR~1/apps/qgis/./python/plugins\TestPlugin\__init__.py", line 26, in classFactory
    from testplugin import TestPlugin
  File "C:/PROGRA~1/QGISBR~1/apps/qgis/./python\qgis\utils.py", line 460, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:/PROGRA~1/QGISBR~1/apps/qgis/./python/plugins\TestPlugin\testplugin.py", line 29, in 
    from testplugindialog import TestPluginDialog
  File "C:/PROGRA~1/QGISBR~1/apps/qgis/./python\qgis\utils.py", line 460, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:/PROGRA~1/QGISBR~1/apps/qgis/./python/plugins\TestPlugin\testplugindialog.py", line 24, in 
    from ui_testplugin import Ui_TestPlugin
ImportError: cannot import name Ui_TestPlugin

Python version: 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]

  • I think you have to place your compiled folder here: C:\Users\(your user name)\.qgis2\python\plugins. See if this works. – Joseph Nov 12 '14 at 10:52
  • did you do pyuic4 -o ui_buildertest.py ui_buildertest.ui ? – Luigi Pirelli Nov 12 '14 at 16:53
1

Thanks for your suggestions, all considered yesterday, before I filed the question.

Solved: something silly, but finally paid attention:

I had not changed the object name for the dialog object in QT. I assumed in error, that the name was generic/default, and carried as such over to the plugin builder. Once I changed the dialog object name, it worked. The hint came from the class name's mismatch within compiled code.

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.