pyinstaller打包python GUI程序

Pyinstaller打包py GUI小程序

GUI小程序(wxpython)

环境 :PyInstaller-3.4、python3.5
下载 :pip install Pyinstaller
下载安装包 :PyInstaller-3.4.tar 解压

打包MainUI

第一步:Win+R 打开切到解压的PyInstaller-3.4 文件夹下
pyinstaller打包python GUI程序
第二步:输入要打包的文件MainUI.py(建议一开始打包可以不去掉控制台,运行时可以找到错误)
pyinstaller打包python GUI程序
不带控制台:pyinstaller.exe -F -i E:\Pythonwork\GUIProject\images\logo.ico E:\Pythonwork\GUIProject\MainUI.py --noconsole
带控制台:pyinstaller.exe -F -i E:\Pythonwork\GUIProject\images\logo.ico E:\Pythonwork\GUIProject\MainUI.py
隐式导入缺少包
pyinstaller.exe -F -i E:\Pythonwork\GUIProject\images\logo.ico E:\Pythonwork\GUIProject\MainUI.py --noconsole
–hidden-import Crypto.Math --hidden-import PyQt5.QtCore

遇到问题

1、配置文件路径,打包后点击exe文件报错,找不到配置文件,默认加载的是c盘

//旧 文件路径
project_dir = os.path.dirname(os.path.abspath(__file__))
//修改后
dir = os.path.realpath(sys.argv[0])
project_dir = os.path.dirname(os.path.abspath(dir))

2、程序打包后,需要把配置文件放置在exe文件同目录下
pyinstaller打包python GUI程序
pyinstaller 打包后的可执行文件可以脱离python环境运行,其他打包工具没试过