我一直在梳理堆棧溢出,並就如何將數據文件添加到我的Python應用程序的Web的休息:任何人使用Pyinstaller成功將數據文件捆綁到一個文件中?
import Tkinter
class simpleapp_tk(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.parent = parent
self.initialize()
def initialize(self):
self.grid()
--- Everything Fine Here ---
self.B = Tkinter.Button(self, text = 'Create Document', command = self.OnButtonClick)
self.B.grid(column = 0, row = 6)
def OnButtonClick(self):
createDoc()
if __name__ == "__main__":
app = simpleapp_tk(None)
app.title('Receipt Form')
app.iconbitmap(os.getcwd() + '/M.ico')
app.mainloop()
我已經使用的.spec文件,沒有運氣試圖
Onedir工作正常,但是當我嘗試編譯爲單個可執行文件時,它會給出文件'M.ico'未定義的錯誤。
如果有人能夠將帶有pyinstaller的數據文件捆綁到一個文件中。請幫忙。謝謝。
我運行的Python 2.7與3.2 PyInstaller
我認爲你的問題是'pyinstaller' [使用臨時文件夾來提取文件](https://pythonhosted.org/PyInstaller/advanced-topics.html#bootloader)。你已經指定在你的代碼中完成凍結應用程序[這裏](http://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile)。 – Repiklis
@Repiklis好的,我該如何使用它呢?我應該怎麼做'app.iconbitmap(resource_path('/ M.ico'))' –
它與[this]非常相似(http://stackoverflow.com/questions/38874563/pypandoc-in-combination-with-pyinstaller/ 38957523#38957523)。您必須將您的圖標包含在spec文件的'resources'中,並在代碼的答案底部添加兩行(在設置圖標之前)。如果您仍有問題,請告訴我。 – Repiklis