时隔将近一年,又要把pyqt5的一些东西拾起来了,好多东西都已经忘了,为了避免再次以往,这里把开发需要准备的东西记录下来。
>>> sudo apt install python3-pyqt5
>>> sudo apt install qttools5-dev-tools
>>> sudo apt install pyqt5-dev-tools
>>> pip3 install pyinstaller
大致开发过程:
- Qt Designer搭建界面,生成 .ui文件
- .ui转为.py(pyuic5 -o a.py a.ui)
- 写界面响应逻辑代码
- pyinstaller打包为.exe文件
2020-03-02更新
使用pyinstaller打包过程中,正常生成可执行文件,但是在运行该可执行文件中出现:
>>> Traceback (most recent call last):
>>> File "PyInstaller/loader/rthooks/pyi_rth_pkgres.py", line 13, in <module>
>>> File "/home/xiang/.local/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
>>> exec(bytecode, module.__dict__)
>>> File "pkg_resources/__init__.py", line 86, in <module>
>>> ModuleNotFoundError: No module named 'pkg_resources.py2_warn'
>>> [24536] Failed to execute script pyi_rth_pkgres
通过添加忽略可解决
>>> pyinstaller --hidden-import pkg_resources.py2_warn example.py
参考:https://stackoverflow.com/a/59979390
2020-03-02更新
给应用添加图标:
>>> pyinstaller --hidden-import pkg_resources.py2_warn -i icon/logo.ico -F example.py
其中.ico格式图片可通过比特虫网站生成
ico路径必须为相对路径