写了一个 Python 程序,想要打包成 exe 文件,就利用 PyInstaller 进行打包。

我的环境:Win 7 64 位,Python 3.7 64位

1、安装 PyInstaller
pip install PyInstaller

2、进行打包
pyinstaller -F MainWindow.py
若成功,就会在 ./dist 文件夹中找到 MainWindow.exe 。但是,大概率会失败。

出现错误:lib not found
PyInstaller 打包 exe
解决:打包时指定依赖的 dll 路径,pyinstaller -p C:\Users\Administrator\AppData\Local\Programs\Python\Python36\Lib\site-packages\shiboken2 -F MainWindow.py(这个 dll 所在路径我是通过 Everything 搜索找到的)
PyInstaller 打包 exe
出现问题:
No module named ‘xxx’
could not import module ‘xxx’
PyInstaller 打包 exe
PyInstaller 打包 exe
解决:添加 --hidden-import typing --hidden-import PySide2.QtXml,那么最终命令为:pyinstaller -p C:\Users\Administrator\AppData\Local\Programs\Python\Python36\Lib\site-packages\shiboken2 -F MainWindow.py --hidden-import typing --hidden-import PySide2.QtXml

相关文章: