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. ImportError: DLL load failed while importing QtCore: The specified module could not be found.
Forum Updated to NodeBB v4.3 + New Features

ImportError: DLL load failed while importing QtCore: The specified module could not be found.

Scheduled Pinned Locked Moved Unsolved Qt for Python
qt for pythonpython
13 Posts 6 Posters 52.8k 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 Marceepoo
    15 Sept 2020, 03:26

    @JKSH said in ImportError: DLL load failed while importing QtCore: The specified module could not be found.:

    from PyQt5.QtWidgets import QApplication, QLabel

    app = QApplication([])
    label = QLabel("Hello World!")
    label.show()

    app.exec_()

    Dear @JKSH
    Thank you so much helping. I tried running Spyder, but it would not run. So I uninstalled Anaconda, downloaded the current version from Anaconda (Anaconda3-2020.07-Windows-x86_64.exe). I closed every running program that I could close, and then reinstalled Anaconda (using the .exe file identified above), while logged into Win10 64 bit Windows as the Win10 administrator.
    Then, I opened the Anaconda prompt as administrator (even though I was logged into Windows as administrator), and ran the command:

    conda install -c anaconda pyqt
    

    On the one hand, Spyder succeeded in running the "Hello World" script you suggested I run.
    But on the other hand, here's what transpired in the Command Prompt window:

    C:\Users\marc>"C:\ProgramData\Anaconda3\python.exe" "E:\Apps\UtilitiesByMarc\Getting the version numbers of Qt, SIP and PyQt.py"
    Python version:  3.8.3 (default, Jul  2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)]
    Version info.:  sys.version_info(major=3, minor=8, micro=3, releaselevel='final', serial=0)
    sys.hexversion:  50856944
    Traceback (most recent call last):
      File "E:\Apps\UtilitiesByMarc\Getting the version numbers of Qt, SIP and PyQt.py", line 9, in <module>
        from PyQt5.QtCore import QT_VERSION_STR
    ImportError: DLL load failed while importing QtCore: The specified module could not be found.
    C:\Users\marc>
    

    I would appreciate any suggestions you might have. I had this problem posted for 14 days ago on StackOverflow, and only got one suggestion which did not help. I don't know where else to turn.

    J Offline
    J Offline
    JKSH
    Moderators
    wrote on 15 Sept 2020, 12:32 last edited by JKSH
    #4

    Hi @Marceepoo, you're most welcome.

    @Marceepoo said in ImportError: DLL load failed while importing QtCore: The specified module could not be found.:

    On the one hand, Spyder succeeded in running the "Hello World" script you suggested I run.

    Great! That means PyQt5 is installed and working.

    But on the other hand, here's what transpired in the Command Prompt window:

    The regular Windows Command Prompt does not have Anaconda's Python environment set up. You should:

    • Run python.exe from your Anaconda Prompt, OR
    • Open your script using Spyder and run it there.

    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

    M 1 Reply Last reply 15 Sept 2020, 21:16
    1
    • J JKSH
      15 Sept 2020, 12:32

      Hi @Marceepoo, you're most welcome.

      @Marceepoo said in ImportError: DLL load failed while importing QtCore: The specified module could not be found.:

      On the one hand, Spyder succeeded in running the "Hello World" script you suggested I run.

      Great! That means PyQt5 is installed and working.

      But on the other hand, here's what transpired in the Command Prompt window:

      The regular Windows Command Prompt does not have Anaconda's Python environment set up. You should:

      • Run python.exe from your Anaconda Prompt, OR
      • Open your script using Spyder and run it there.
      M Offline
      M Offline
      Marceepoo
      wrote on 15 Sept 2020, 21:16 last edited by
      #5

      @JKSH Again, I can't thank you enough.
      Proving the truth of the old adage, "No good deed goes unpunished", I have a follow up question.
      Hereunto, when I have run a python script, I usually ran it either:

      • As a "Tool" in EditPad Pro, which I think ran my scripts under the Windows Cmd.exe, as follows:
      "C:\ProgramData\Anaconda3\python.exe" "%Python_FILE%" 
      

      or

      • In a .cmd file, or as a command line being run by vbscript, or by python's subprocess.

      [Confession: I don't know whether those uses of Cmd.exe called the Cmd.exe in: (i) C:\Windows\System32, or (ii) C:\Windows\SysWOW64]

      So I went hunting for Anaconda's version of Cmd.exe, thinking maybe the command line syntax would be:

      [Full Path to Anaconda's Cmd.exe] "C:\ProgramData\Anaconda3\python.exe" "%Python_FILE%" 
      

      I checked the Windows properties for the Anaconda Prompt's shortcut to get the shortcut's "Target", i.e., the Full Path to (what I presumed would be) Anaconda's analog to "cmd.exe".
      But the shortcut's Target was a little more complicated, to wit:

      %windir%\System32\cmd.exe "/K" C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3
      

      I am out of my league here. I have no idea how to use that.

      What would be the proper command line on a Windows to run, in the Anaconda Prompt, a python script located at "e:\apps\PyQt5script.py"?

      Thanks again,
      Marc

      J 1 Reply Last reply 15 Sept 2020, 21:24
      0
      • M Marceepoo
        15 Sept 2020, 21:16

        @JKSH Again, I can't thank you enough.
        Proving the truth of the old adage, "No good deed goes unpunished", I have a follow up question.
        Hereunto, when I have run a python script, I usually ran it either:

        • As a "Tool" in EditPad Pro, which I think ran my scripts under the Windows Cmd.exe, as follows:
        "C:\ProgramData\Anaconda3\python.exe" "%Python_FILE%" 
        

        or

        • In a .cmd file, or as a command line being run by vbscript, or by python's subprocess.

        [Confession: I don't know whether those uses of Cmd.exe called the Cmd.exe in: (i) C:\Windows\System32, or (ii) C:\Windows\SysWOW64]

        So I went hunting for Anaconda's version of Cmd.exe, thinking maybe the command line syntax would be:

        [Full Path to Anaconda's Cmd.exe] "C:\ProgramData\Anaconda3\python.exe" "%Python_FILE%" 
        

        I checked the Windows properties for the Anaconda Prompt's shortcut to get the shortcut's "Target", i.e., the Full Path to (what I presumed would be) Anaconda's analog to "cmd.exe".
        But the shortcut's Target was a little more complicated, to wit:

        %windir%\System32\cmd.exe "/K" C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3
        

        I am out of my league here. I have no idea how to use that.

        What would be the proper command line on a Windows to run, in the Anaconda Prompt, a python script located at "e:\apps\PyQt5script.py"?

        Thanks again,
        Marc

        J Offline
        J Offline
        JonB
        wrote on 15 Sept 2020, 21:24 last edited by JonB
        #6

        @Marceepoo said in ImportError: DLL load failed while importing QtCore: The specified module could not be found.:

        %windir%\System32\cmd.exe "/K" C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3

        This simply starts a cmd.exe, which first runs C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3 to set up the anaconda environment, and the cmd (Command Prompt) remains (does not exit). You then sit and execute things.

        Anaconda does not have "its own" command shell, it's just the regular Windows one. With some variables set up as per C:\ProgramData\Anaconda3\Scripts\activate.bat.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Marceepoo
          wrote on 18 Sept 2020, 20:00 last edited by
          #7

          Do you know if there a way for me to send a command line (e.g.: ' "python.exe" "hello_world.py" ') to the Anaconda environment after I run the activate.bat?

          I tried running:

          %windir%\System32\cmd.exe "/K" C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3 E:\Apps\UtilitiesByMarc\PyQt5_Hello_World.py
          

          But I got the error message,

          activate does not accept more than one argument:
          ['C:\\ProgramData\\Anaconda3', 'E:\\Apps\\UtilitiesByMarc\\PyQt5_Hello_World.py']
          

          So, looking for another alternative, I opened an Anaconda prompt and then found it in Taskmgr's processes window, and then opened the Details link for that process, and got a PID of 15124.
          One idea I had is:

          • I would run a Vbscript that would call/trigger the Anaconda prompt shortcut and get the PID of the instance of cmd.exe that the shortcut created; and then, ...

          • I would use the PID to somehow send to that instance of cmd.exe, the following command line:

          ' "C:\ProgramData\Anaconda3\python.exe" "e:\hello_world.py" '
          

          Of course, I haven't yet figured out how to do that.

          I would appreciate any suggestions about where to get help that would enable me to use PyQt for the python scripts I use for copying files, performing searches for files or in files, etc.

          Thank you again.
          Marc

          J 1 Reply Last reply 20 Sept 2020, 08:22
          0
          • J Offline
            J Offline
            JKSH
            Moderators
            wrote on 19 Sept 2020, 12:16 last edited by
            #8

            Just call Anaconda's activate.bat script before calling your own script:

            > C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3
            
            > python.exe E:\Apps\UtilitiesByMarc\PyQt5_Hello_World.py
            

            (Note: After activating, python.exe will be placed in your PATH so you don't need to specify the full path anymore)

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            2
            • M Marceepoo
              18 Sept 2020, 20:00

              Do you know if there a way for me to send a command line (e.g.: ' "python.exe" "hello_world.py" ') to the Anaconda environment after I run the activate.bat?

              I tried running:

              %windir%\System32\cmd.exe "/K" C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3 E:\Apps\UtilitiesByMarc\PyQt5_Hello_World.py
              

              But I got the error message,

              activate does not accept more than one argument:
              ['C:\\ProgramData\\Anaconda3', 'E:\\Apps\\UtilitiesByMarc\\PyQt5_Hello_World.py']
              

              So, looking for another alternative, I opened an Anaconda prompt and then found it in Taskmgr's processes window, and then opened the Details link for that process, and got a PID of 15124.
              One idea I had is:

              • I would run a Vbscript that would call/trigger the Anaconda prompt shortcut and get the PID of the instance of cmd.exe that the shortcut created; and then, ...

              • I would use the PID to somehow send to that instance of cmd.exe, the following command line:

              ' "C:\ProgramData\Anaconda3\python.exe" "e:\hello_world.py" '
              

              Of course, I haven't yet figured out how to do that.

              I would appreciate any suggestions about where to get help that would enable me to use PyQt for the python scripts I use for copying files, performing searches for files or in files, etc.

              Thank you again.
              Marc

              J Offline
              J Offline
              JonB
              wrote on 20 Sept 2020, 08:22 last edited by JonB
              #9

              @Marceepoo
              I am a little lost as to what you are actually trying to achieve.

              Are you trying to run this python stuff outside of Qt? Are the python scripts your actual Qt application? Are you trying to run these python scripts as sub-processes from your Qt application via QProcess? Or what?

              If you are sitting in your own Command Prompt you can just execute two statements like @JKSH shows. The first sets the environment used by the second. You can also then continue to execute further python scripts in that shell by only doing the second line (python.exe ...) as the environment has been set from the first line.

              Earlier on you were using cmd.exe /K, which creates a new Command Prompt and Keeps it in existence. (Where cmd.exe /C would run a command and then exit the Command Prompt.) I'm not sure how that relates to your situation/what you want to happen.

              To do normal conda development work, one normally opens a Command Prompt and type in the first command, to set that shell's environment. You could set up a shortcut like cmd /k C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3 to achieve that. Then you keep that and keep typing in the various python.exe ... lines to run things. If you want the first thing it does to be the "Hello World" then do the "Hello", and then stay, you can do that in one line/from a shortcut via:

              cmd /k "C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3 & python.exe E:\Apps\UtilitiesByMarc\PyQt5_Hello_World.py"
              
              M 1 Reply Last reply 20 Sept 2020, 17:20
              0
              • J JonB
                20 Sept 2020, 08:22

                @Marceepoo
                I am a little lost as to what you are actually trying to achieve.

                Are you trying to run this python stuff outside of Qt? Are the python scripts your actual Qt application? Are you trying to run these python scripts as sub-processes from your Qt application via QProcess? Or what?

                If you are sitting in your own Command Prompt you can just execute two statements like @JKSH shows. The first sets the environment used by the second. You can also then continue to execute further python scripts in that shell by only doing the second line (python.exe ...) as the environment has been set from the first line.

                Earlier on you were using cmd.exe /K, which creates a new Command Prompt and Keeps it in existence. (Where cmd.exe /C would run a command and then exit the Command Prompt.) I'm not sure how that relates to your situation/what you want to happen.

                To do normal conda development work, one normally opens a Command Prompt and type in the first command, to set that shell's environment. You could set up a shortcut like cmd /k C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3 to achieve that. Then you keep that and keep typing in the various python.exe ... lines to run things. If you want the first thing it does to be the "Hello World" then do the "Hello", and then stay, you can do that in one line/from a shortcut via:

                cmd /k "C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3 & python.exe E:\Apps\UtilitiesByMarc\PyQt5_Hello_World.py"
                
                M Offline
                M Offline
                Marceepoo
                wrote on 20 Sept 2020, 17:20 last edited by
                #10

                @JonB said in ImportError: DLL load failed while importing QtCore: The specified module could not be found.:

                cmd /k "C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3 & python.exe E:\Apps\UtilitiesByMarc\PyQt5_Hello_World.py"

                That was the exactly the solution I was looking for. Thank you sooo much. Often for me, the hardest part is explaining what I am trying to do without providing too long a description. Thank you for seeing what I needed, and showing me how to do it. Much appreciated.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  romankris
                  wrote on 29 Mar 2021, 06:50 last edited by
                  #11

                  The solution is to provide the python interpreter with the path-to-your-module. The simplest solution is to append that python path to your sys.path list. In your notebook, first try:

                  import sys
                  sys.path.append('my/path/to/module/folder')
                  

                  This isn't a permanent change in sys.path, because when you log out, your environment is reset, so any variables you may have set are lost.

                  The better (and more permanent) way to solve this is to set your PYTHONPATH, which provides the interpreter with additional directories look in for python packages/modules.

                  from BASH type: export PYTHONPATH=/path/to/new/folder:/another/path/...../ #each path must be separated by a colon
                  
                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    catafest
                    wrote on 24 Jan 2023, 20:56 last edited by
                    #12

                    You need to reinstall PyQt6 with this command in Windows OS:

                    pip3 install PyQt6 --user --ignore-installed
                    

                    Make a search with my nickname catafest and you will find my blog about python

                    R 1 Reply Last reply 4 Mar 2024, 03:06
                    2
                    • C catafest
                      24 Jan 2023, 20:56

                      You need to reinstall PyQt6 with this command in Windows OS:

                      pip3 install PyQt6 --user --ignore-installed
                      

                      Make a search with my nickname catafest and you will find my blog about python

                      R Offline
                      R Offline
                      redstoneleo
                      wrote on 4 Mar 2024, 03:06 last edited by
                      #13

                      @catafest Works great ! Thank you!

                      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