Include a json file with exe pyinstaller

前端 未结 2 1141
花落未央
花落未央 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')
    
    0 讨论(0)
  • 2021-01-24 13:10

    I converted the python application to exe with pyinstaller using below cmmand

    pyinstaller --onefile main.py
    

    and then I copied the json file to the dist folder created by pyinstaller and it worked. hope this helps you to resolve this issue.

    Note : I havent included any resource command with pyinstaller

    0 讨论(0)
提交回复
热议问题