Pyinstaller:生成-exe文件+文件夹(在--onefile模式下) [英] Pyinstaller: generate -exe file + folder (in --onefile mode)

查看:1329
本文介绍了Pyinstaller:生成-exe文件+文件夹(在--onefile模式下)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在使用Pyinstaller. 我有一个脚本,可以从img文件夹中获取图像.

Now i'm working with Pyinstaller. I have an script which get images from a img folder..

/python
|----/img
|----|----icon1.ico
|----|----icon2.ico
|----maint.py

我生成.exe的脚本是

My script to generate .exe is

pyinstaller.py --windowed --noconsole --clean --onefile maint.py

问题在于仅生成.exe文件,但整个文件夹/img被省略.

the problem is that only generate the .exe file but the whole folder /img is omitted.

问题:为了自动获取.exe文件+/img文件夹,我需要在上一行中添加哪种附加语法?

更新12/18/2013

我的意思是:执行完pyinstaller.py脚本并包含所有参数后,我必须在/dist文件夹中看到:.exe文件+/img文件夹,其中包含我拥有的所有图标或位图文件应用

谢谢

推荐答案

更新12/19/2013

最后,我们明白了!

0.我正在使用最新版本的PYInstaller + Python 2.67,并以Sublime Text作为编辑器.

1.如果您的Py脚本需要一些文件,图标,图像,则必须包括一个从项目文件夹(正在开发中)检索这些文件或从临时数据文件夹中检索(如果部署)的函数.该脚本必须完全在代码中您放置亲戚路径的部分中,以获取资源.请严格遵循以下准则: https://stackoverflow.com/a/13790741

2.在前面的代码之后,您必须第一次执行pyinstaller命令-正如我在问题中发布的那样-.

3.现在,打开执行PYInstaller(位于PYinstaller/)命令后生成的.spec文件,并在"a.binaries"行之后,将下一行添加到EXE()函数中:

Finally, we got it!

0. I'm working with current version of PYInstaller + Python 2.67 with Sublime Text as Editor.

1. In case your Py script requires some files, icons, images, you must include a function which retrieves these files from the project folder (in development) or form the temporary data folder (in case of deployment). This script MUST be in your code exactly in the part which you put the relatives paths in order to get the resources. Please follow exactly this guideline: https://stackoverflow.com/a/13790741

2. After the previous code, you must execute for the first time the pyinstaller command -as I post in my question post-.

3. Now, open your .spec file generated after execution of the PYInstaller (located in PYinstaller/) command and add, after "a.binaries" line, the next line into the EXE() function:

exe = EXE(pyz,
          a.scripts,
          a.binaries,
          Tree('..\\python\\images', prefix='images\\'),
....

请记住,在 Tree(...)函数中,第一个参数是要放置在外部的文件夹:这意味着我要包含此文件夹的所有内容(请注意,我正在将相对于AppStart.py文件的相对路径)放入我的.EXE文件的文件容器中.

4.修改后,重新执行pyinstaller命令,但在这种情况下,指向我的.SPEC文件:

Keep in mind that in Tree(...) function the first argument is the folder to put outside: which means that I want to include all the content of this folder (notice that I'm putting a relative path respect to the AppStart.py file) into the file's container of my .EXE file.

4. After that modification re-execute the pyinstaller command, but in this case pointing to my .SPEC file:

pyinstaller.py --windowed --noconsole --clean --onefile AppStart\AppStart.spec

最后,我的应用程序可以执行为可执行文件,而无需像提到的人那样复制并粘贴所有外部文件夹. 但我还是一如既往地考虑良好的做法.

And finally my App can be executed as executable without need to copy and paste all external folders as someone mentioned. But as always I consider the good-practical way.

感谢您的支持.

这篇关于Pyinstaller:生成-exe文件+文件夹(在--onefile模式下)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆