While doing a first-time attempt to craft a simple plugin, I ran into this error:
ImportError: cannot import name
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?
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)]
Best Answer
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.