关于pyinstall打包时的依赖问题

 前几天写了一个人脸表情分析的小程序,想用pyinstall打包成一个可以移植的小软件。因为之前用过pyinstall,所以这次使用同样的方法对我的程序进行打包:

【pyinstaller -F --icon=图标.ico 要打包的文件.py --noconsole】

其中【-F】参数表示打包后生成单一的文件。pyinstall还有其他的一些参数可供选择:

What to generate:

-F, --onefile

create a single file deployment

-D, --onedir

create a single directory deployment (default)

-o DIR, --out=DIR

create the spec file in directory. If not specified, and the current directory is Installer’s root directory, an output subdirectory will be created. Otherwise the current directory is used.

-n NAME, --name=NAME

optional name to assign to the project (from which the spec file name is generated). If omitted, the basename of the (first) script is used.

但是当我使用之前同样的方法打包完成后,也生成了一个exe程序,双击执行的时候,什么也没有发生。在pycharm中运行良好的程序,到exe就什么都没有了,最恐怖的是连报错都没有!!

这时,可以使用【-C】参数,生成控制台版本的exe程序。这样会在【dist】文件夹下生成一个以程序命名的文件夹,在这个文件夹中会有这个exe程序。

我们在控制台下执行这个程序,如果程序无法正常执行的话,会输出错误信息:

看来我的错误是因为无法打开这个dat文件,我想起来我在程序中用到了这个数据文件,可能打包的时候,pyinstall没有吧这个需要的依赖文件装进exe程序中。

这时一种方法是吧这个dat文件拷贝进这个exe所在的文件夹中。

另一种方法就是修改【spec】文件。

打开spec文件,在datas参数里面添加依赖文件的路径

然后重新打包这个spec文件:【pyinstall from_video.spec】即可。

posted @ 2018-04-22 22:01  Andrew_qian  阅读(1765)  评论(0编辑  收藏  举报