Has anyone successfully linked data files into a single file using Pyinstaller?

I combed Qaru and the rest of the Internet on how to add data files to a python application:

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()

I tried using .spec file with no luck

Onedir works fine, however, when I try to compile it into a single executable file, it gives an error that the "M.ico" file is not defined.

If someone was able to link the data files with pyinstaller into one file. Please help. Thank you

I am on a computer running Windows 10 with Python 2.7 with PyInstaller 3.2

+4
source share
1 answer

, .spec pyinstaller, (.spec .) .spec "datas":

# -*- mode: python -*-

block_cipher = None


a = Analysis(['pubdata.py'],
             pathex=['.', '/interface','/recommender'],
             binaries=None,
             datas=[('WordNet/*.txt','WordNet'),
             ('WordNet/*.json','WordNet'),
             ('WordNet/pdf_parsing/*.json','pdf_parsing'),
             ('WordNet/pdf_parsing/*.xml','pdf_parsing'),
             ('images/*.png','images'),
             ('database/all_meta/Flybase/*.txt','all_meta'),
             ('database/all_meta/Uniprot/*.txt','all_meta'),
             ('database/json_files/*.json','json_files'),
             ('Data.db','.')],

             hiddenimports=['interface','recommender'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='GUI',
          debug=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='GUI')
app = BUNDLE(coll,
             name='App.app',
             icon=None)

, , .spec, Pyinstaller _MEIPASS . Data.db:

import sys
import os.path

        if hasattr(sys, "_MEIPASS"):
            datadir = os.path.join(sys._MEIPASS, 'Data.db')
        else:
            datadir = 'Data.db'

        conn = lite.connect(datadir)

, :

conn = lite.connect("Data.db")

, : https://irwinkwan.com/2013/04/29/python-executables-pyinstaller-and-a-48-hour-game-design-compo/

, !

+2

Source: https://habr.com/ru/post/1651254/


All Articles