使用 exe pyinstaller 包含一个 json 文件 [英] Include a json file with exe pyinstaller
问题描述
我已经阅读了 pyinstaller 的文档几个小时了.我无法理解如何使用选项 --resource RESOURCE
I have been reading the documentation of the pyinstaller for hours. I cannot understand how to use the option --resource RESOURCE
它说
-r 资源,--resource 资源
向 Windows 可执行文件添加或更新资源.RESOURCE
是一对四项,**FILE[,TYPE[,NAME[,LANGUAGE]]]**
.FILE
可以是数据文件或 exe/dll.对于数据文件,至少必须指定TYPE
和NAME
.LANGUAGE
默认为 0 或可以指定为通配符 * 以更新给定 TYPE
和 NAME
的所有资源.对于 exe/dll 文件,如果 TYPE
、NAME
和 LANGUAGE<,
FILE
中的所有资源将被添加/更新到最终的可执行文件中/code> 被省略或指定为通配符 *
.此选项可以多次使用.
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 leastTYPE
andNAME
must be specified.LANGUAGE
defaults to 0 or may be specified as wildcard * to update all resources of the givenTYPE
andNAME
. For exe/dll files, all resources fromFILE
will be added/updated to the final executable ifTYPE
,NAME
andLANGUAGE
are omitted or specified as wildcard*
. This option can be used multiple times.
我不明白 **FILE[,TYPE[,NAME[,LANGUAGE]]]]**
是什么意思.这是我正在使用的命令
I do not understand what **FILE[,TYPE[,NAME[,LANGUAGE]]]**
means. This is the command I am using
pyinstaller test.py -F -r=test.json
应该是test.json[,JSON[,test]]
吗?
谢谢.
推荐答案
我不确定您是否还需要帮助,但这应该可以帮助未来从 google 来到这里的人.使用首次在 py 脚本上运行 pyinstaller 时生成的规范文件.从那里你可以添加 json 和其他数据文件,如下所示
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')
这篇关于使用 exe pyinstaller 包含一个 json 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!