Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Import error : cannot import name OptionsTRANUSDialog
Forum Updated to NodeBB v4.3 + New Features

Import error : cannot import name OptionsTRANUSDialog

Scheduled Pinned Locked Moved Unsolved Language Bindings
python
7 Posts 2 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    I have a strange problem : ImportError: cannot import name OptionsTRANUSDialog In the file OptionsTRANUSDialog, I can get my checked_list by this method :

    model = self.scenarios.model()
    checked_indexes = model.match(model.index(0, 0), QtCore.Qt.CheckStateRole,QtCore.Qt.Checked, -1,QtCore.Qt.MatchExactly | QtCore.Qt.MatchRecursive)
    
    for index in checked_indexes:
        item = model.itemFromIndex(index)
        item_text = item.text()
        self.checked_list.append(item_text)
    
    if self.checked_list != [] :
        dialog = LaunchTRANUSDialog(parent=self)
        dialog.show()
        result = dialog.exec_()
    

    I want to use this checked_list in another file(launch_tranus_dialog), so I put the import in this file :

    from .Options_TRANUS_dialog import OptionsTRANUSDialog
    

    And when I execute I get this error : ImportError: cannot import name OptionsTRANUSDialog

    I really don't understand this import error. I verify that my files are located in the same directory.

    Could you help me please.

    Thanks.

    JohanSoloJ 1 Reply Last reply
    0
    • ? A Former User

      I have a strange problem : ImportError: cannot import name OptionsTRANUSDialog In the file OptionsTRANUSDialog, I can get my checked_list by this method :

      model = self.scenarios.model()
      checked_indexes = model.match(model.index(0, 0), QtCore.Qt.CheckStateRole,QtCore.Qt.Checked, -1,QtCore.Qt.MatchExactly | QtCore.Qt.MatchRecursive)
      
      for index in checked_indexes:
          item = model.itemFromIndex(index)
          item_text = item.text()
          self.checked_list.append(item_text)
      
      if self.checked_list != [] :
          dialog = LaunchTRANUSDialog(parent=self)
          dialog.show()
          result = dialog.exec_()
      

      I want to use this checked_list in another file(launch_tranus_dialog), so I put the import in this file :

      from .Options_TRANUS_dialog import OptionsTRANUSDialog
      

      And when I execute I get this error : ImportError: cannot import name OptionsTRANUSDialog

      I really don't understand this import error. I verify that my files are located in the same directory.

      Could you help me please.

      Thanks.

      JohanSoloJ Offline
      JohanSoloJ Offline
      JohanSolo
      wrote on last edited by
      #2

      @EJWA said in Import error : cannot import name OptionsTRANUSDialog:

      I really don't understand this import error. I verify that my files are located in the same directory.

      Could you help me please.

      The line from .Options_TRANUS_dialog import OptionsTRANUSDialog looks suspicious to me: is your file containing the definition of OptionsTRANUSDialog names .Options_TRANUS_dialog .py?

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      ? 1 Reply Last reply
      1
      • JohanSoloJ JohanSolo

        @EJWA said in Import error : cannot import name OptionsTRANUSDialog:

        I really don't understand this import error. I verify that my files are located in the same directory.

        Could you help me please.

        The line from .Options_TRANUS_dialog import OptionsTRANUSDialog looks suspicious to me: is your file containing the definition of OptionsTRANUSDialog names .Options_TRANUS_dialog .py?

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        @JohanSolo
        Hi,

        The file Options TRANUSDialog is containing the class OptionsTRANUSDialog.

        1 Reply Last reply
        0
        • JohanSoloJ Offline
          JohanSoloJ Offline
          JohanSolo
          wrote on last edited by
          #4

          @EJWA said in Import error : cannot import name OptionsTRANUSDialog:

          The file Options TRANUSDialog is containing the class OptionsTRANUSDialog.

          With a space? I doubt this can ever work...

          `They did not know it was impossible, so they did it.'
          -- Mark Twain

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Yes the same structure works for other imports.

            Example :

            from .scenarios_model import ScenariosModel
            from .launch_tranus_dialog import LaunchTRANUSDialog

            1 Reply Last reply
            0
            • JohanSoloJ Offline
              JohanSoloJ Offline
              JohanSolo
              wrote on last edited by
              #6

              Usually, the files to be imported are located in another directory, with a __init__.py script, which lists the available files. Then, you can easily do from ModuleDirectory import src_file, where ModudeDirectory contains the file src_file.py file.

              I tried to quickly look at the import documentation, and found nothing about spaces (i.e. neither a forbidden statement nor a special syntax where the spaces are replaces with underscores).

              If I were you, I'd remove all spaces in the file / directory names (which sounds like heresy to me, especially when coming to programming), and then I'd give another try.

              `They did not know it was impossible, so they did it.'
              -- Mark Twain

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                For more information, here is the error that I get : Couldn't load plugin OptionsTRANUS due to an error when calling its classFactory() method

                ImportError: cannot import name OptionsTRANUSDialog Traceback (most recent call last): File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 333, in startPlugin plugins[packageName] = package.classFactory(iface) File "C:/Users/emna/.qgis2/python/plugins\OptionsTRANUS__init__.py", line 34, in classFactory from .Options_TRANUS import OptionsTRANUS File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 607, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:/Users/emna/.qgis2/python/plugins\OptionsTRANUS\Options_TRANUS.py", line 30, in from .OptionsTRANUS_project import OptionsTRANUSProject File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 607, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:/Users/emna/.qgis2/python/plugins\OptionsTRANUS\OptionsTRANUS_project.py", line 24, in from .Options_TRANUS_dialog import OptionsTRANUSDialog File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 607, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:/Users/emna/.qgis2/python/plugins\OptionsTRANUS\Options_TRANUS_dialog.py", line 29, in from .launch_tranus_dialog import LaunchTRANUSDialog File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 607, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:/Users/emna/.qgis2/python/plugins\OptionsTRANUS\launch_tranus_dialog.py", line 7, in from .Options_TRANUS_dialog import OptionsTRANUSDialog ImportError: cannot import name OptionsTRANUSDialog

                Python version: 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)] QGIS version: 2.18.3 Las Palmas, 77b8c3d

                Python Path: C:/OSGEO4~1/apps/qgis/./python C:/Users/emna/.qgis2/python C:/Users/emna/.qgis2/python/plugins C:/OSGEO4~1/apps/qgis/./python/plugins C:\OSGEO4~1\apps\Python27\lib\site-packages\setuptools-0.9.8-py2.7.egg C:\OSGEO4~1\bin\python27.zip C:\OSGEO4~1\apps\Python27\DLLs C:\OSGEO4~1\apps\Python27\lib C:\OSGEO4~1\apps\Python27\lib\plat-win C:\OSGEO4~1\apps\Python27\lib\lib-tk C:\OSGEO4~1\bin C:\OSGEO4~1\apps\Python27 C:\OSGEO4~1\apps\Python27\lib\site-packages C:\OSGEO4~1\apps\Python27\lib\site-packages\jinja2-2.7.2-py2.7.egg C:\OSGEO4~1\apps\Python27\lib\site-packages\markupsafe-0.23-py2.7-win-amd64.egg C:\OSGEO4~1\apps\Python27\lib\site-packages\pytz-2012j-py2.7.egg C:/Users/emna/.qgis2//python

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved