Pyinstaller打包程序缓存问题
问题描述
Windows系统使用Pyinstaller打包Python程序exe
,使用exe程序中发现前后执行结果不一致,第二次调用程序产生的数据中含有第一次执行程序的数据,猜测可能是代码逻辑或Pyinstaller打包程序有缓存的问题
,经排查排除第一种情况。然后百度
第二种情况,找不到相关的答案;可以切换至必应
或谷歌
搜索问题(最好使用英文描述问题)。最终在官网找到解决方法
,其中一段描述是这样的:
If you share the same home directory on multiple platforms, for example GNU/Linux and OS X,
you will need to set the PYINSTALLER_CONFIG_DIR environment variable (换行为了方便展示全文)
to different values on each platform otherwise PyInstaller may cache files
for one platform and use them on the other platform,
as by default it uses a subdirectory of your home directory as its cache location.
大致描述提到了打包程序的缓存问题。
解决方案
- 删除打包项目下与项目无关的缓存文件
- 使用Pyinstaller的命令选项
--clean
进行打包(进行这两步基本上不会再出现问题
)
--clean: 在构建之前清理PyInstaller缓存并删除临时文件
-D: 创建包含可执行文件的单文件夹包,同时会有一大堆依赖的 dll 文件,这是默认选项
-F: 只生成一个 .exe 文件,如果项目比较小的话可以用这个,但比较大的话就不推荐
出问题时使用的命令:
pyinstaller -F xxx.py
解决问题时使用的命令:
pyinstaller -F --clean xxx.py
pyinstaller其他参数的使用不做介绍,可以自行百度