0
点赞
收藏
分享

微信扫一扫

可执行文件的转换(.py转.exe),PyInstaller解决生成的文件为.exe.notanexecutable等报错

晚安大世界 2022-03-18 阅读 31

安装PyInstaller

pip install pyinstaller

准备一个.py文件和一个图片,在两个文件所在的文件夹下运行cmd进行合成

结果爆出如下错误

ValueError: Received icon path ‘M:python文件写入测试exe合成?2.png’ which exists but is not in the correct format. On Windows, only ‘.ico’ images or other ‘.exe’ files may be used as icons. Please convert your ‘.png’ file to a ‘.ico’ and try again.

原因是需要将图片格式更改为.ico

再次运行

结果爆出如下错误,并且生成的.exe文件为magzhu.exe.notanexecutable,不可执行

struct.error: unpack requires a buffer of 16 bytes

这里只需使用在线转换ico工具来转换图片就可以了,需要转换成尺寸为16*16
使用在线转换成ico的工具即可

链接:https://onlineconvertfree.com/

先将图片转换为ico格式,再将ico格式图片进行切割

然后再次执行

pyinstaller -F -w -i picture_compress.ico magzhu.py

在dist内的文件也变为了.exe程序

举报

相关推荐

0 条评论