参考
安装问题:
python打包exe报错:Fatal error: PyInstaller does not include a pre-compiled bootloader for your platform.
PyInstaller does not include a pre-compiled bootloader…,Checking for ‘msvc‘ C compiler
pyinstaller:AttributeError: ‘NoneType’ object has no attribute ‘find_module’
使用问题:
使用pyinstaller打包exe文件遇到的问题总结
解决pyinstaller 打包后运行exe程序出现的"ModuleNotFindError"
pyinstaller系列之五:使用 --add-data 打包额外资源
Pyinstaller打包完整python项目 使用虚拟环境的python项目的打包
安装
建议不要直接pip install pyinstaller,这样后面打包的时候会报错
PyInstaller does not include a pre-compiled bootloader...
-
在官方网站上下载源码包:
https://github.com/pyinstaller/pyinstaller/releases -
源码包解压
-
执行
// 进入目录并执行语句
cd bootloader
python ./waf all
// 安装
cd ..
python setup.py install
注意:建议下载pyinstaller4.0版本,我是python3.7环境,下载了4.5和4.4版本打包时出现错误:
pyinstaller:AttributeError: 'NoneType' object has no attribute 'find_module'
打包并测试
pyinstaller的参数可以参考:
使用pyinstaller打包exe文件遇到的问题总结
打包:
pyinstaller main.py -D -p /usr/local/lib/python3.7/dist-packages
测试:
cd dist/main/
./main
报错:有一些第三方库没有成功打包(主要是rknn相关的)
ModuleNotFindError
重新打包:
- 打开main.py同级目录下生成的main.spec文件,修改hiddenimports:
hiddenimports=['psutil', 'rknnlite','ruamel.yaml'],
- 终端输入:
pyinstaller main.spec
测试:
cd dist/main/
./main
报错:ModuleNotFind :rknnlite.api.xxx(rknn仍然没有完全打包)
打开dist/main/rknnlite文件夹以及/usr/local/lib/python3.7/dist-packages/rknnlite,对比可以发现打包仍然缺失了一些文件
解决:
直接将本地rknnlite库复制到dist/main/里
cp -r /usr/local/lib/python3.7/dist-packages/rknnlite/ /home/xxx/xxx/dist/main/
测试again:
./main
报错:(其实是打包时只打包了py文件,项目中的其他文件以及文件夹没有被一起打包)
解决:
打开main.spec文件,修改datas:
datas=[('./inference_dataset','inference_dataset'), ('./rknnmodel','rknnmodel'), ('info.cfg', '.')],
重新打包并且加上rknn库
pyinstaller main.spec
cp -r /usr/local/lib/python3.7/dist-packages/rknnlite/ /home/xxx/xxx/dist/main/
最后测试:
cd dist/main/
./main
成功运行!!!
把dist文件夹进行压缩,里面已经包括整个项目的文件以及环境配置