Pyinstaller打包pyqt5文件全过程

步骤1

确保已经安装了pyinstaller包
可用pip命令,也可以在pycharm里面安装(推荐)
如果你安装了matplotlib库,确保版本低于3.2,可以在pycharm中更换版本

步骤2

找到要打包的文件的父目录,shift + 右键进入命令行窗口
确保命令行属性中的当前代码页采用的编码是utf-8
Pyinstaller打包pyqt5文件全过程
如果如上图所示不是utf-8,则键入 chcp 65001 切换至utf-8(编码格式可能会影响pyinstaller命令)
Pyinstaller打包pyqt5文件全过程
然后使用pyinstaller -F demo3.py命令打包文件
Pyinstaller打包pyqt5文件全过程
Pyinstaller打包pyqt5文件全过程
打包完成

步骤3

打包完之后有多了三样东西:1.dist文件夹(放置打包后的.exe文件)2.build文件夹 3.demo3.spec文件
我们在pycharm中打开demo3.spec文件
更改 hiddenimports=[], 至 hiddenimports=[‘matplotlib’],
Pyinstaller打包pyqt5文件全过程

最后重新进行打包
键入命令 pyinstaller -F demo3.spec
Pyinstaller打包pyqt5文件全过程
Pyinstaller打包pyqt5文件全过程
成功运行,如果你不想显示命令行就改变pyinstaller的参数 pyinstaller -F -w demo3.py就行了
要给.exe文件换图标就把.ico文件和py文件放在一起,打包时 pyinstaller -F -w -i 图片名.ico 文件名.py就行了