最近使用PyQt5做一个小程序,程序功能简单;程序做玩后,运行比较卡顿,深觉需要学习的东西还有很多.
觉得python还是做数据处理比较适合.用来做桌面开发或者大程序,就不太适合.
1,PyQt5打包
安装pyinstaller
pip install pyinstaller
#打包
pyinstaller -i xxx.ico -F xxx.py -w
#-w 不带黑窗口
注意:由于程序中使用了pymssq库,所以打包之前,需要在主程序中导入_mssql包;同时还需要导入其他包.
import _mssql,uuid,decimal
在GUI中,可能会引用某些图片,将图片打包在exe内部调用,会方便很多.
#创建img.qrc
<!DOCTYPE RCC>
<RCC>
<qresource>
<file alias="IMG/1.png">IMG/1.png</file>
<file alias="IMG/2.png">IMG/2.png</file>
<file alias="IMG/3.png">IMG/3.png</file>
<file alias="IMG/4.png">IMG/4.png</file>
<file alias="IMG/database.png">IMG/database.png</file>
<file alias="IMG/index.png">IMG/index.png</file>
<file alias="IMG/information.png">IMG/information.png</file>
<file alias="IMG/mail.png">IMG/mail.png</file>
<file alias="IMG/stcd.png">IMG/stcd.png</file>
<file alias="IMG/window_bg.png">IMG/window_bg.png</file>
</qresource>
</RCC>
#将img.qrc转换为python包img.py
pyrcc5 -o img.py img.qrc
#在python代码中调用图片
:/IMG/1.png
转载于:https://blog.51cto.com/we17ha/1917418