Search code examples
pythonpyqtpyinstallerexecutablepyqt6

Create PyQt6 Python Project Executable


I code a Qt project in python 3.8 using PyQt6. When I run python file by python, no problem. When I try to convert project to executable, it fails. I faced to so many problems and I solved them as looking in google. Howeveri I couldn't find a solution for belove fail.

This application failed to start because no QT platform plugin could be initialized. Reinstalling the application may fix this problem

I use auto-py-to-exe to create executable by belove command

pyinstaller --noconfirm --onedir --windowed --icon "D:/WorkSpace/Projects/MouseReplayer/output/icon/icon2.ico" --name "Auto Test Repeater" --add-data "D:/WorkSpace/Projects/MouseReplayer/ScreenCopy;ScreenCopy/"
--add-data "D:/WorkSpace/Projects/MouseReplayer/ui;ui/" --paths "C:/Users/26010693/AppData/Local/Programs/Python/Python38/Lib/site-packages/PyQt6/Qt/bin"
--hidden-import "PyQt6.sip"  "D:/WorkSpace/Projects/MouseReplayer/ui_main.py"

I tried to reinstalling but didn't work. Actually, this problem is common in PyQt5 and according to Youtube, There is a easy solution to fix it(Youtube Solution) that Copying platform folder(PyQt5\Qt\plugins\platforms) into Pyqt5-tools folder, all in Python\Python38\Lib\site-packages. However there is no Pyqt6-tools folder in site-packages and no installation guide on internet.

I need to help to solve it or find another way to create executable compatible for PyQt6


Solution

  • Copying dll files in Python\Python38\Lib\site-packages\PyQt5\Qt\plugins\platformsinto directly executable output folder is solved the issue. My recent pyinstaller command that:

    pyinstaller --noconfirm --onedir --windowed --icon "D:/WorkSpace/Projects/MouseReplayer/output/icon2.ico" --name "Auto Test Player" --add-data "D:/WorkSpace/Projects/MouseReplayer/ScreenCopy;ScreenCopy/" --add-data "D:/WorkSpace/Projects/MouseReplayer/ui;ui/" --paths "C:/Users/26010693/AppData/Local/Programs/Python/Python38/Lib/site-packages/PyQt6/Qt/bin" --hidden-import "PyQt6.sip" --hidden-import "PyQt6.QtPrintSupport" --add-data "C:/Users/26010693/AppData/Local/Programs/Python/Python38/Lib/site-packages/PyQt6/Qt/plugins/platforms;platforms/"  "D:/WorkSpace/Projects/MouseReplayer/ui_main.py"
    

    key line to fix is that:

    --add-data "C:/Users/26010693/AppData/Local/Programs/Python/Python38/Lib/site-packages/PyQt6/Qt/plugins/platforms;platforms/" 
    

    and also below line is to prevent another issue:

    --hidden-import "PyQt6.sip"
    

    may be this one also important:

    --hidden-import "PyQt6.QtPrintSupport"