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. Unable to import PySide2
Forum Updated to NodeBB v4.3 + New Features

Unable to import PySide2

Scheduled Pinned Locked Moved Unsolved Qt for Python
16 Posts 9 Posters 19.1k Views
  • 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.
  • P Offline
    P Offline
    Pit96
    wrote on last edited by
    #1

    Hello everyone,

    I am new to the QT Creator on Mac and when I first started to run a simple standard widget I got the "ImportError" as you can see in the screenshot. I checked my installation of PySide2 with "pip install PySide2" but it seems to be installed. Can anyone give me a hint on how to solve the problem? Thanks in advance!
    Peter

    Output:

    Traceback (most recent call last):
      File "/Users/XYZ/DropSizeGetter_NEW/dropsizegetter.py", line 3, in <module>
        from PySide2.QtWidgets import QApplication, QWidget
    ImportError: No module named PySide2.QtWidgets
    

    Screenshot

    jsulmJ 1 Reply Last reply
    0
    • P Pit96

      Hello everyone,

      I am new to the QT Creator on Mac and when I first started to run a simple standard widget I got the "ImportError" as you can see in the screenshot. I checked my installation of PySide2 with "pip install PySide2" but it seems to be installed. Can anyone give me a hint on how to solve the problem? Thanks in advance!
      Peter

      Output:

      Traceback (most recent call last):
        File "/Users/XYZ/DropSizeGetter_NEW/dropsizegetter.py", line 3, in <module>
          from PySide2.QtWidgets import QApplication, QWidget
      ImportError: No module named PySide2.QtWidgets
      

      Screenshot

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Pit96 said in Unable to import PySide2:

      PySide2

      Do you have more than one Python installation?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Pit96
        wrote on last edited by
        #3

        I am not 100% sure but when I check via "python --version" I get: Python 3.7.4
        I am pretty sure that I still have a version of Python 2.7.

        jsulmJ 1 Reply Last reply
        0
        • P Pit96

          I am not 100% sure but when I check via "python --version" I get: Python 3.7.4
          I am pretty sure that I still have a version of Python 2.7.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Pit96 That could be the reason: you installed PySide2 in one Python version but you tries to use it with another Python version.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Pit96
            wrote on last edited by
            #5

            I checked my Python versions again with pyenv. It says that I have system as a Python-Version (should be Python 2.7 which is shipped with MacOS) and Python 3.7.4 (marked with a * ). How can I install PySide2 for different Python Versions?

            jsulmJ 1 Reply Last reply
            0
            • P Pit96

              I checked my Python versions again with pyenv. It says that I have system as a Python-Version (should be Python 2.7 which is shipped with MacOS) and Python 3.7.4 (marked with a * ). How can I install PySide2 for different Python Versions?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Pit96 On Linux pip for Python3 is called pip3. So, I guess you installed for Python2. Check whether you have pip3.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • P Offline
                P Offline
                Pit96
                wrote on last edited by
                #7

                When I type in "pip3 install pyside2" or "pip install pyside2" it always says: Requirement already satisfied. So it should be installed for both versions.

                JonBJ 1 Reply Last reply
                1
                • P Pit96

                  When I type in "pip3 install pyside2" or "pip install pyside2" it always says: Requirement already satisfied. So it should be installed for both versions.

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

                  @Pit96
                  For both pip & pip3 you can go pip[3] list to list what actually is installed. I would look through that, carefully, If what it is complaining about is indeed installed, then I can only guess that where you are trying to run your code from is not using where you pip installed to, e.g. inside/outside a virtual environment? I am unsure whether message ImportError: No module named PySide2.QtWidgets is telling you PySide2 found but no QtWidgets there, or whether it means no PySide2 at all, you might play with that.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Pit96
                    wrote on last edited by
                    #9

                    @JonB So I followed your suggestion and also copied the code to PyCharm. When I did that it still said that it cannot find PySide2 but it asked me if I want to install it. After I did it the code worked in PyCharm. I also checked if PySide2 is installed for both Python Versions and it is. So I guess it is really a problem regarding a virtual environment. My question is now how do I know if my QT Creator App is working inside/outside a virtual environment? Thanks in Advance!

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      deleted533
                      wrote on last edited by
                      #10
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        dalilander
                        wrote on last edited by
                        #11

                        Old topic but same problem but it solved for me like this:

                        pip3 list and pip list both showed PySide2 as installed. In Qt/Options I noticed Python 2.7 as default. Changed this to 3.6 and then when trying to compile I was asked to install some more stuff. After that everything worked.

                        G 1 Reply Last reply
                        1
                        • D dalilander

                          Old topic but same problem but it solved for me like this:

                          pip3 list and pip list both showed PySide2 as installed. In Qt/Options I noticed Python 2.7 as default. Changed this to 3.6 and then when trying to compile I was asked to install some more stuff. After that everything worked.

                          G Offline
                          G Offline
                          gheeto
                          wrote on last edited by
                          #12

                          @dalilander Hi there, hey I'm having the same problem. What do you mean by Qt/Options - where do I find these options to change this to 3.7 (for me).

                          I'm working with 3.7.3 on a Windown 10 machine. Anaconda Navagator to manage packages. I'm quite new to all of this so any information would be great.

                          V 1 Reply Last reply
                          0
                          • G gheeto

                            @dalilander Hi there, hey I'm having the same problem. What do you mean by Qt/Options - where do I find these options to change this to 3.7 (for me).

                            I'm working with 3.7.3 on a Windown 10 machine. Anaconda Navagator to manage packages. I'm quite new to all of this so any information would be great.

                            V Offline
                            V Offline
                            vardaan
                            wrote on last edited by
                            #13

                            @gheeto Tools->Options->Python->Python 3.7.3. That's what he means to say, that didn't work for me though. I have python 3.8.2 does that make it a problem?

                            J 1 Reply Last reply
                            2
                            • V vardaan

                              @gheeto Tools->Options->Python->Python 3.7.3. That's what he means to say, that didn't work for me though. I have python 3.8.2 does that make it a problem?

                              J Offline
                              J Offline
                              Johnny_5
                              wrote on last edited by
                              #14

                              @vardaan I'm having the same problem in Qt Creator 4.11.1 and Neon 20.04. Importing works fine in Idle but doesn't in QT Creator or if run from terminal.

                              jsulmJ 1 Reply Last reply
                              0
                              • J Johnny_5

                                @vardaan I'm having the same problem in Qt Creator 4.11.1 and Neon 20.04. Importing works fine in Idle but doesn't in QT Creator or if run from terminal.

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @Johnny_5 Please show the code and error message

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0
                                • Y Offline
                                  Y Offline
                                  Yaser.F
                                  wrote on last edited by
                                  #16

                                  Follow the steps ( @Pit96 ) ==> open your project python and then click Projects >>Build & Run >> Run Settings >> Interpreter >> click Manage and set Python 3 or Python 2

                                  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