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.5k 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.
  • M Offline
    M Offline
    Mindful
    wrote on 4 Sept 2021, 09:22 last edited by
    #1

    Hello everyone! I'm having a problem with PyQt5: I would like to open a .py document, but when I try to open it in my Mac terminal, it doesn't work. The terminal say that there is no module named 'widgets', but 'widgets' is not a module, it's a directory. In the 'widgets' folder there is the 'gui_.py' file that i would like to open. It contain the Ui_MainWindow class that I would like to import.Schermata 2021-09-04 alle 11.09.22.png Schermata 2021-09-04 alle 11.10.08.png Schermata 2021-09-04 alle 11.10.30.png Schermata 2021-09-04 alle 11.11.02.png
    How can I solve the problem?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 4 Sept 2021, 22:03 last edited by
      #2

      Hi,

      Where does that .ui come from ?
      How did you generate the Python code from it ?
      Which version of PyQt5 are you using ?

      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
      0
      • M Offline
        M Offline
        Mindful
        wrote on 7 Sept 2021, 08:28 last edited by Mindful 9 Jul 2021, 08:30
        #3

        Hi @SGaist, I am using QtDesigner tool from Qt to create the ui files and after the creation of them I am using the command:

        pyuic5 -o <the name of the file we wish to generate in .py format> <the name of the ui file generated by QtCreator in ui format>
        Ex: pyuic5 -o mygui.py mygui.ui

        pyuic5 comes from python ui compiler (or converter, probably) and 5 which comes from the version of pyqt. For the resources file we are doing the same thing but using the resources compiler from Pyqt5 which is called pyrcc5. For the third question the answer is: Pyqt5 version 5.9.2

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 7 Sept 2021, 19:50 last edited by
          #4

          Can you show the structure of your application ?
          It seems there might be some issue with that.

          If you are using sub folders, did you think about adding the __init__.py file 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

          M 1 Reply Last reply 5 Oct 2021, 14:15
          0
          • S SGaist
            7 Sept 2021, 19:50

            Can you show the structure of your application ?
            It seems there might be some issue with that.

            If you are using sub folders, did you think about adding the __init__.py file in it ?

            M Offline
            M Offline
            Mindful
            wrote on 5 Oct 2021, 14:15 last edited by Mindful 10 May 2021, 14:18
            #5

            @SGaist I’m sorry for the latency in answering you but I was trying to solve the problem on my own. Unfortunately I didn’t succeed because even today the terminal said that it can’t find subfolders that are in the main one. In its opinion they don’t exist. “Adding the __init.py__file”: what does it mean?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 5 Oct 2021, 18:46 last edited by
              #6

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

              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 6 Oct 2021, 07:07
              0
              • S SGaist
                5 Oct 2021, 18:46

                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 6 Oct 2021, 07:07 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
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 6 Oct 2021, 07:10 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 6 Oct 2021, 11:31
                  0
                  • S SGaist
                    6 Oct 2021, 07:10

                    Shouldn't that be:

                    from .Model.standard_item import StandardItem
                    

                    ?

                    Notice the starting ..

                    M Offline
                    M Offline
                    Mindful
                    wrote on 6 Oct 2021, 11:31 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
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 6 Oct 2021, 19:11 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 8 Oct 2021, 10:57
                      0
                      • S SGaist
                        6 Oct 2021, 19:11

                        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 8 Oct 2021, 10:57 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 30 Dec 2022, 13:57
                        0
                        • S SGaist
                          6 Oct 2021, 19:11

                          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 10 Oct 2021, 14:39 last edited by Mindful 10 Oct 2021, 14:40
                          #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 30 Dec 2022, 12:36
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 10 Oct 2021, 18:23 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
                              10 Oct 2021, 14:39

                              @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 30 Dec 2022, 12:36 last edited by
                              #14

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

                              JonBJ 1 Reply Last reply 30 Dec 2022, 12:43
                              0
                              • F Filipe_Portugal
                                30 Dec 2022, 12:36

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

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on 30 Dec 2022, 12:43 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
                                  8 Oct 2021, 10:57

                                  @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 30 Dec 2022, 13:57 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