Ado, anyway, I'm not successful, but I record what pit encountered!
1: Install the relevant library is too slow
Solution: offline installation
In a lot of tutorial, you want to install several libraries, but some libraries use pip install on-line has been stuck (see the progress bar when the card will go die), this problem can be solved using an offline installation, attached below solve process!
Installation error (in fact, is too slow, I am forced to stop)
Solutions are as follows:
First, find the download link this library, here is this:
Then use other HTTP download tool, I use the IDM, you can also use your browser!
Then open storage directory,
Here then open the command line,
Then here the first pit is solved, this method is suitable for installation in all libraries (official or slow when you need to install third-party libraries)! !
第二个坑,调试没问题,运行就报错(代码错误)
在这里我确定使用py文件运行是没问题的,但是打包之后却提示我没有定义exit变量/函数(exit是系统变量)
对于这个问题我暂时的解决办法有两个,要么舍弃这个退出功能,否则无法打包,要么定义这个函数!
我的退出原代码为,这样子是打包不了的,至少我打包的时候是这样
怎么去定义我就不细说了,能写出程序的人看了这个方法都会懂的
那么第二个坑就解决了(虽然我发现定义了之后点击退出却没有反应,这个可以点X关闭,所以我就先不管了)
第三个坑:运行提示Failed to execute script main
首先,执行构建命令:
然后查看文件列表
将配置文件(背景文件)放在一起!
最后运行程序!----------------------居然不报错了!
首先确保所需文件都在你写的相对目录里,例如我这个程序调用的背景写的是
找到这个.spec文件,使用文本编辑(在这里我用vim工具),下面第二张图(VIM);
windows用户建议使用Notepad++,下面第三张图(Notepad++)
反正就是在.spec里面修改一下参数,首先找到
a = Analysis
接下来继续压缩!
在打包程序的时候是不会打包图片文件的,但是我们可以把图片文件转为py文件,所以解决这个背景问题的关键点就是这个了,下面附上一些别人的教程!
Pyinstaller 使用+打包图片方法
下面是我的打包记录。
首先安装相关库
http://imgbase64.duoshitong.com/
转换之后就需要调用,调用方法如下
首先需要导入base64库以及OS库
所以需要添加的代码有两部分,第一部分是库导入
Well, here disguised to solve the problem of the image files can not be packaged, then reseal the program to see