Python- packaged

A, QRC file integration of resources
  resource files used by the program (pictures, audio and qss , etc.) if not directly packaged and packaged with the program code to exe executable file to go, that is to say after the exe file which must be the same path the availability of resources file, this time in order to allow the resource file and the program code with packaged into exe file, need to use qrc file
1, first create a res.qrc in the project, enter

<RCC>
	<qresource prefix="res/">
		<file alias="图片名称.png">res/图片名称.png</file>
		<file alias="音频名称.wav">res/音频名称.wav</file>
		<file alias="style.qss">res/style.qss</file>
	</qresource>
</RCC>

prefix is the prefix of the resource file in the code we write is res /. <file>Tag content is written in the path of the resource file, alias attribute is written, the resource file name. A ** label corresponds to a resource file.
2, the command line window with pyrcc5 tool to convert it to py files (pyrcc5 included in PyQt5)
command line format: pyrcc5 source file -o output file
Here Insert Picture Description
and then we will find more than a project directory res.py file
3, China imported last step in the code we just get res.py file, and add a path in front of the response “:”(plus: that access to resources from res.py rather than in the res folder)
increase as modified

import res
self.setWindowIcon(QIcon(':res/图片名称.png'))
self.btn_sound(':res/音频名称.wav'))
qss_style = read_qss(':res/style.css')

Qic should create a file created when the program began to write, whenever a new file is added directly to the resource qrc in)

Second, with PyInstaller pack
1 download pyinstaller

pip install pyinstaller
parameter usefulness
-F Will be packaged into one file
-w Remove the black box
-i Add program desktop icon, followed immediately ico format icon path

Enter the following command in the project path

pyinstaller -F -w -i ./res/ico名称.ico 文件.py

Here Insert Picture Description
Generated under the project directory and buildd dist folder and a .spec file, we need to exe files in the dist folder,
double-click the .exe file, if the display program interface description package successful
if the bomb box appears, put the pack command -w remove the package once again. After this there will be packaged black box, black box in an error message, the error message can be resolved.
Here Insert Picture Description
Error Solution can go to the link query

Pyinstaller package of solutions to the problem Summary: https://blog.csdn.net/La_vie_est_belle/article/details/82260339

Published 70 original articles · won praise 25 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_36318271/article/details/104097644