Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. No module named 'widgets', but it is a directory, not a module
Forum Updated to NodeBB v4.3 + New Features

No module named 'widgets', but it is a directory, not a module

Scheduled Pinned Locked Moved Unsolved Qt for Python
qt for pythonpython
16 Posts 4 Posters 2.7k 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.
  • SGaistS SGaist

    Literally that: adding a file named __init__.py in the folder. However it might not be needed anymore with Python 3.

    M Offline
    M Offline
    Mindful
    wrote on last edited by
    #7

    @SGaist the problem persist, it said that there isn’t any module name “Model”, but Model is a folder. Inside it there is the Standard_Item file that i want to import:

    From Model.standard_item import StandardItem
    ModuleNotFoundError: No module named ‘Model’
    

    Do you think it could be a venv problem?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #8

      Shouldn't that be:

      from .Model.standard_item import StandardItem
      

      ?

      Notice the starting ..

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        Shouldn't that be:

        from .Model.standard_item import StandardItem
        

        ?

        Notice the starting ..

        M Offline
        M Offline
        Mindful
        wrote on last edited by
        #9

        @SGaist with the starting . the terminal said:

        from .Model.standard_item import StandardItem
        ImportError: attempted relative import with no known parent package
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #10

          Would it be possible for you to provide a minimal project that shows that issue so we can debug that from the same source ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          M 2 Replies Last reply
          0
          • SGaistS SGaist

            Would it be possible for you to provide a minimal project that shows that issue so we can debug that from the same source ?

            M Offline
            M Offline
            Mindful
            wrote on last edited by
            #11

            @SGaist of course! What part of the code would be more useful for you? I could paste it here

            F 1 Reply Last reply
            0
            • SGaistS SGaist

              Would it be possible for you to provide a minimal project that shows that issue so we can debug that from the same source ?

              M Offline
              M Offline
              Mindful
              wrote on last edited by Mindful
              #12

              @SGaist here I am. I solved the problem by adding a line of code at the beginning of the main file:

              sys.path.append(r’/Users/[user]/Desktop/[folder name]’)
              

              It identifies the path to the folder that contains the other subfolders. Thanks for your time!

              F 1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #13

                When using that technique you should rather determine the location of the current script using __file__ so that you don't hard code the path in it.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • M Mindful

                  @SGaist here I am. I solved the problem by adding a line of code at the beginning of the main file:

                  sys.path.append(r’/Users/[user]/Desktop/[folder name]’)
                  

                  It identifies the path to the folder that contains the other subfolders. Thanks for your time!

                  F Offline
                  F Offline
                  Filipe_Portugal
                  wrote on last edited by
                  #14

                  @Mindful i have this problem.~
                  you can explain better how you solve?

                  JonBJ 1 Reply Last reply
                  0
                  • F Filipe_Portugal

                    @Mindful i have this problem.~
                    you can explain better how you solve?

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #15

                    @Filipe_Portugal
                    See https://www.geeksforgeeks.org/file-a-special-variable-in-python/ for __file__. Use that if you need the path to the Python script file/directory rather than hard-coding it.

                    1 Reply Last reply
                    0
                    • M Mindful

                      @SGaist of course! What part of the code would be more useful for you? I could paste it here

                      F Offline
                      F Offline
                      Filipe_Portugal
                      wrote on last edited by
                      #16

                      @Mindful i have this problem.~
                      you can explain better how you solve?

                      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