Include a json file with exe pyinstaller

前端 未结 2 1142
花落未央
花落未央 2021-01-24 12:06

I have been reading the documentation of the pyinstaller for hours. I cannot understand how to use the option --resource RESOURCE

It says

-r RES

2条回答
  •  一个人的身影
    2021-01-24 13:07

    Im not sure if you still need help, but this should help future people who come here from google. Use the spec file that is made when you first run pyinstaller on a py script. From there you can add json and other data files like below

     # -*- mode: python -*-
    
    block_cipher = None
    
    added_files = [
             ( 'configREs.json', '.'),  # Loads the '' file from
                                        # your root folder and outputs it with
                                        # the same name on the same place.
             ]
    
    
    a = Analysis(['gui.pyw'],
                 pathex=['D:\\OneDrive\\Programming\\Python Projects\\Python'],
                 binaries=[],
                 datas=added_files,
                 hiddenimports=[],
                 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='name here',
              debug=False,
              strip=False,
              upx=True,
              console=False, icon='iconname.ico', version='version.rc' )
    coll = COLLECT(exe,
                   a.binaries,
                   a.zipfiles,
                   a.datas,
                   strip=False,
                   upx=True,
                   name='gui')
    

提交回复
热议问题