Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Error in my first Qt5 program
Forum Updated to NodeBB v4.3 + New Features

Error in my first Qt5 program

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
21 Posts 5 Posters 9.5k Views 2 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
    Mikenitin92
    wrote on last edited by
    #1

    Hi all,

    I have installed Qt5 and python 3.6.0. I am unable to run a simple hello world program.

    See below my error:
    from PyQt5.QtWidgets import QApplication, QLabel
    ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5/QtWidgets.so, 2): Symbol not found: __os_activity_create
    Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5/Qt/lib/QtCore.framework/Versions/5/QtCore (which was built for Mac OS X 10.12)
    Expected in: /usr/lib/libSystem.B.dylib
    in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5/Qt/lib/QtCore.framework/Versions/5/QtCore

    Can someone please help. I think there is a problem with my Qt5 Install on my Mac OS X El Capitan. Can someone please help me with the right commands to install Qt5 or Qt4? Appreciate your help! :)

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

      Hi and welcome to devnet,

      How did you install both ?

      Since you are using Python and PyQt, the most simple way is to create a virtual environment using python's virtualenv, activate it and then call pip install PyQt5.

      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 Offline
        M Offline
        Mikenitin92
        wrote on last edited by
        #3

        Hi Thanks for your help!
        Yes I did create a venv folder and I think I ran the above command to install PyQt5. Do I have to place my .py file inside that folder and run it?

        Nitin.

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

          No, you have to ensure that you properly activated the virtual environment before installing anything in it and also before running your application.

          From the looks of it, you have rather installed PyQt5 system wide.

          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 Offline
            M Offline
            Mikenitin92
            wrote on last edited by
            #5

            I tried to install PyQt5 all over again, activate it and when I tried to run the program I got the following error:

            (qtproject) (base) Nitins-MacBook-Pro:pluralsight Nitin$ python3 structure.py
            Traceback (most recent call last):
            File "structure.py", line 1, in <module>
            from PyQt5.QtWidgets import *
            ModuleNotFoundError: No module named 'PyQt5.QtWidgets'

            Do you know how I can import these modules?

            Nitin

            jsulmJ 1 Reply Last reply
            0
            • M Mikenitin92

              I tried to install PyQt5 all over again, activate it and when I tried to run the program I got the following error:

              (qtproject) (base) Nitins-MacBook-Pro:pluralsight Nitin$ python3 structure.py
              Traceback (most recent call last):
              File "structure.py", line 1, in <module>
              from PyQt5.QtWidgets import *
              ModuleNotFoundError: No module named 'PyQt5.QtWidgets'

              Do you know how I can import these modules?

              Nitin

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

              @Mikenitin92 said in Error in my first Qt5 program:

              from PyQt5.QtWidgets import *

              Works for me (I installed PyQt5 using pip3 system wide), if it does not for you then you either did not install PyQt5 correctly or you're not using the virtual environment where you installed PyQt5.

              Did you consider what @SGaist wrote in hes last post in this thread?

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

              1 Reply Last reply
              1
              • M Offline
                M Offline
                Mikenitin92
                wrote on last edited by
                #7

                Hi all,

                I have done the following steps:

                1. I already have Python 3.6.0 installed system wide.
                2. Created a new virtual environment and activated it
                  - pip install virtualenv
                  - virtualenv nitin_venv
                  - cd nitin_venv
                  - source bin/activate
                3. Install PyQt5
                  • pip install PyQt5
                4. Placed a . py file in my virtual environment(nitin_venv folder) and tried to execute it
                  - python3 ~/.nitin_venv/sample.py

                Then I received the import error, not sure where I am doing it wrong.

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

                  Might be a silly question but did you check that python3 is really the one from your virtual environment ?

                  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

                    Might be a silly question but did you check that python3 is really the one from your virtual environment ?

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

                    @SGaist I did not check. How can I check if python3 is from my virtual environment?

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

                      Run which python3 in the terminal you use to execute your script.

                      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
                        Mikenitin92
                        wrote on last edited by
                        #11

                        That gave me ~/.nitin_venv/bin/python. So, I think python is from my virtual environment. Also, Do I have to run the my python program from my virtual environment?

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

                          The file doesn't need to be in there, the virtual environment is there to provide you with the dependencies you need in a controlled fashion.

                          Can you show the code you are using to test that ?

                          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
                            Mikenitin92
                            wrote on last edited by
                            #13

                            Sure.
                            Here it is!

                            from PyQt5.QtWidgets import *
                            import sys
                            app = QApplication([])
                            label = QLabel('Hello world!')
                            label.show()
                            app.exec_()

                            JonBJ 1 Reply Last reply
                            0
                            • M Mikenitin92

                              Sure.
                              Here it is!

                              from PyQt5.QtWidgets import *
                              import sys
                              app = QApplication([])
                              label = QLabel('Hello world!')
                              label.show()
                              app.exec_()

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

                              @Mikenitin92
                              If your problem seems to be something about not being to find libraries such that Qt apps can't be run then this probably has nothing to do with it. But I don't think you can write a Qt app to just "display a label nowhere" as per your code (you need a window or a dialog etc.). Did you get this code from somewhere/do you have a problem when it runs, or are you still at the ImportError just trying to get going?

                              1 Reply Last reply
                              1
                              • M Offline
                                M Offline
                                Mikenitin92
                                wrote on last edited by
                                #15

                                Hi,

                                I have tested with a new sample file which is:
                                print ("Hi")
                                from PyQt5.QtWidgets import *

                                And this is the output:
                                Hi
                                Traceback (most recent call last):
                                File "/Users/Nitin/PycharmProjects/pluralsight/nitin_venv/lib/test.py", line 2, in <module>
                                from PyQt5.QtWidgets import *
                                ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5/QtWidgets.so, 2): Symbol not found: __os_activity_create
                                Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5/Qt/lib/QtCore.framework/Versions/5/QtCore (which was built for Mac OS X 10.12)
                                Expected in: /usr/lib/libSystem.B.dylib
                                in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5/Qt/lib/QtCore.framework/Versions/5/QtCore

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

                                  @Mikenitin92 said in Error in my first Qt5 program:

                                  import sys
                                  app = QApplication([])

                                  Unrelated but to be clean, it should be sys.argv as parameter of QApplication.

                                  What version of PyQt do you have installed ?
                                  Did you try to uninstall your system version of PyQt and re-install it in your virtual environment ?

                                  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
                                    Mikenitin92
                                    wrote on last edited by
                                    #17

                                    Hello,

                                    I have PyQt5. I have deleted the virtual folder and created it again, activated and installed PyQt5. Did I do it right?

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

                                      Yes you did, however PyQt5 is the package name, not its version. However since you just now installed it, it should be the latest version available.

                                      Did you also uninstall the version you have installed system wide ?

                                      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
                                        Mikenitin92
                                        wrote on last edited by
                                        #19

                                        I don't think I have installed PyQt5 system wide. Do you know how I can check if it is installed system wide?

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

                                          @Mikenitin92 said in Error in my first Qt5 program:

                                          /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5/QtWidgets.so

                                          That path makes me think that it is since it's the OS provided Python framework.

                                          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

                                          • Login

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