python - 使用 exe pyinstaller 包含一个 json 文件

标签 python pyinstaller

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

上面写着

-r RESOURCE, --resource RESOURCE

Add or update a resource to a Windows executable. The RESOURCE is one to four items, **FILE[,TYPE[,NAME[,LANGUAGE]]]**. FILE can be a data file or an exe/dll. For data files, at least TYPE and NAME must be specified. LANGUAGE defaults to 0 or may be specified as wildcard * to update all resources of the given TYPE and NAME. For exe/dll files, all resources from FILE will be added/updated to the final executable if TYPE, NAME and LANGUAGE are omitted or specified as wildcard *. This option can be used multiple times.

我不明白什么**FILE[,TYPE[,NAME[,LANGUAGE]]]**方法。这是我正在使用的命令

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

应该是test.json[,JSON[,test]]

谢谢。

最佳答案

我不确定您是否还需要帮助,但这应该对 future 从 Google 来到这里的人有所帮助。使用首次在 py 脚本上运行 pyinstaller 时创建的规范文件。从那里您可以添加 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')

关于python - 使用 exe pyinstaller 包含一个 json 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42100198/

相关文章:

python - 使用 PyInstaller 打包时找不到 SpaCy 模型

python - 网络驱动程序异常 : Message: 'geckodriver' executable needs to be in PATH

python - Pyinstaller - 无法将脚本编译为完全独立的

python - 从 PyInstaller 包访问 Python 解释器

python-3.x - 运行时错误: Cannot find the MXNet library

python - 使用 pyInstaller 创建一个使用 UAC 的 exe

c# - 将 C# 类对象传递给 Python 文件

xml - 如何在 Python 中以简单的方式拆分 XML 文件?

python - KML 到 Python 中的字符串?

python - 使用 pyinstaller 捆绑 redis 服务器