pyinstaller 打包 win32ctypes.pywin32.pywintypes.error: (225, '', '无法成功完成操作,因为文件包含病毒或潜在的垃圾软件。')
背景:
使用python 写了一个程序,使用pyinstaller打包,
不使用-w --noconsole的命令打包隐藏命令行窗口时,是正常的,
但是使用-w或者--noconsole就会报错win32ctypes.pywin32.pywintypes.error: (225, '', '无法成功完成操作,因为文件包含病毒或潜在的垃圾软件。')
在网上搜索了一些资讯,注释了os.path以及print等都不行,
方案:
将pyinstaller 6.3.0,卸载后,安装6.2.0重新打包即可
pip uninstall pyinstaller
pip install pyinstaller==6.2.0
打包命令:
1. 只打一个py文件 --onefile
pyinstaller --onefile XX.py
2. 添加图标文件夹 --add-data
pyinstaller --add-data "icon/*;./icon" --onefile XX.py
3. 不带控制台 -w 或 --noconsole
pyinstaller --add-data "icon/*;./icon" --onefile XX.py --noconsole
4. 排除某些依赖 --exclude-module xxpackagename 如果有多个,就重复
pyinstaller --add-data "icon/*;./icon" -w --exclude-module xxx1 --exclude-module xxx2 --onefile XX.py
5. 设定exe的logo.ico
pyinstaller --icon=D:/logo.ico --add-data "icon/*;./icon" --onefile XXX.py -w