包含带有exe pyinstaller的json文件

时间:2017-02-07 21:19:20

标签: python pyinstaller

我一直在阅读documentation of the pyinstaller几个小时。我无法理解如何使用选项--resource RESOURCE

它说

  

-r RESOURCE, - 资源资源

     
    

将资源添加或更新为Windows可执行文件。 RESOURCE是一个      四个项目,文件[,类型[,名称[,语言]]] 。 FILE可以是数据文件或exe / dll。对于数据文件,必须至少指定TYPE和NAME。 LANGUAGE默认为0或可以指定为通配符*以更新给定TYPE和NAME的所有资源。对于exe / dll文件,如果省略TYPE,NAME和LANGUAGE或指定为通配符*,则将FILE中的所有资源添加/更新到最终可执行文件。此选项可以多次使用。

  

我不明白 FILE [,TYPE [,NAME [,LANGUAGE]]] 的含义。这是我正在使用的命令

  

pyinstaller test.py -F -r = test.json

它应该是test.json [,JSON [,test]]吗?

感谢。

2 个答案:

答案 0 :(得分:2)

我不确定你是否还需要帮助,但这应该有助于未来谷歌来这里的人。使用在py脚本上首次运行pyinstaller时生成的spec文件。从那里你可以添加json和其他数据文件,如下所示

 # -*- 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')

答案 1 :(得分:0)

我使用cmmand下面的pyinstaller将python应用程序转换为exe

pyinstaller --onefile main.py

,然后将json文件复制到pyinstaller创建的dist文件夹中,并且可以正常工作。希望这可以帮助您解决此问题。

注意:我没有在pyinstaller中包含任何资源命令

相关问题