cx_Freeze: ImportError: No module named 'PyQt5.Qt'

前端 未结 3 629
孤独总比滥情好
孤独总比滥情好 2021-01-20 17:57

I am trying to build my GUI application using cx_Freeze. The setup.py is as follows:

from cx_Freeze import setup, Executable
import         


        
相关标签:
3条回答
  • 2021-01-20 18:19

    I know this is an old question, but today I faced this problem.

    This is how I solved it:

    Removed PyQt5 and everything that was related to it from my setup.py ('{"build_exe": {"packages":' <- this part). After it compiled my exe. If you run the exe and theres a missing PyQt5 module error, then from your site-packages directory (path similar to this: d:\Python37\Lib\site-packages\PyQt5\) copy the whole PyQt5 directory to your cx_freeze built lib directory (example: ..\build\exe.win-amd64-3.7\lib\)

    Now try to run the exe and there should be no missing module error, at least related to PyQt5. If you have any other missing module problem, then just copy it from your site-packages into the lib directory. Hope it helps.

    0 讨论(0)
  • 2021-01-20 18:24

    Don't capitalize PyQt5. Try pyqt5 in the setup.py file.

    0 讨论(0)
  • 2021-01-20 18:28

    Try to remove the (unnecessary?) line

    import PyQt5.Qt
    

    from your setup.py script.

    EDIT after the OP removed this line:

    1. Try to remove the unnecessary os.environ statements, these are for tkinter, maybe they conflict. Remove the 3 DLLs entries in the include_files (keep only the icon). Add 'atexit' to the includes list, see the cx_Freeze PyQt5 example.

    2. Try to re-install PyQt5 and cx_Freeze, see potential caveats in ImportError: No module named PytQt5 and PyQt5 and QtGui module not found.

    3. If this still does not work, maybe there is a conflict with another package used in your application. To find out, make a minimal example using only PyQt5, such as the cx_Freeze PyQt5 example and try to freeze it. If it works, add the other packages one by one, checking the frozen application at each step.

    EDIT II:

    1. A further possibility is that you have a conflict with PyQt4 if it is or has been installed on your system. Make sure to remove any import of PyQt4 from your application and maybe add an entry excludes: ['PyQt4'] to the build_exe dictionary in your setup.py script.
    0 讨论(0)
提交回复
热议问题