T
T
tutam2018-05-27 16:12:17
Python
tutam, 2018-05-27 16:12:17

How to properly compile a python program using PyQt5 using pyinstaller?

I tried to build the following PyQt5 program using pyinstaller:

import sys

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QApplication, QLabel

app = QApplication(sys.argv)
w = QLabel()
w.setWindowFlags(Qt.FramelessWindowHint)
w.setAttribute(Qt.WA_TranslucentBackground)
w.setText("Draw text...")
w.setFont(QFont("Times", 25, QFont.Normal))
# w.move(x, y) or center
w.adjustSize()  # update w.rect() now
w.move(app.desktop().screen().rect().center() - w.rect().center())
w.show()
sys.exit(app.exec_())

Everything seems to be going, but when I try to open the collected file, I see the following:
5b0aae09eb185417052827.png
I wrote the following in the console:
pyinstaller --onedir --noconsole --onefile --name=myprogram "C:\Users\tutam\Desktop\Python_experiments\test_pyqt5.py"

If you put the compiled executable in the C:\Users\tutam\AppData\Local\Programs\Python\Python35-32 folder, i.e. in the same folder with the qt.conf file, which contains the paths to pyqt, then everything works fine. But then it is necessary for the user to have pyqt, i.e. is it not a standalone executable?
Has anyone encountered something similar? How did you win?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2018-05-27
@tutam

Here is a link on how to correctly assemble the application, one EXE file works without problems.
Problem pyinstaller Pyqt5 add background.
this means incompatibility between PyQt5 and Python. or something else, it doesn't matter.
The solution is to tear down PyQt5 and install like this:

spoiler
pip install pyqt5
spoiler
pip install pyqt5-tools
By the way, PySide2 will be released soon)

I
ilya_ya, 2018-05-27
@ilya_ya

Here it is from an article on Habré https://habr.com/post/325626/:
The most commonly used options are:
--onefile - assembly into one file, i. .dll files are not written.
--windowed - when the application starts, the console will appear.
--noconsole - when the application starts, the console will not appear.
--icon=app.ico - add an icon to the window.
--paths - the ability to manually enter the path to the necessary files if pyinstaller
cannot find them (for example: --paths D:\python35\Lib\site-packages\PyQt5\Qt\bin)

T
tutam, 2018-05-27
@tutam

At most to collect in a uniform file it did not turn out. If you do not write during assembly --onefile, i.e. not to collect into a single file, then you need to move qwindows.dllfrom dist\PyQt5\Qt\plugins\platforms\qwindows.dllto dist\platforms\qwindows.dll. You can read more about this error here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question