gpt4 book ai didi

python - PyInstaller -- 从脚本添加数据

转载 作者:行者123 更新时间:2023-12-05 05:41:08 32 4
gpt4 key购买 nike

我正在尝试从我的 python 项目中创建一个可执行文件。我正在使用函数“make_executable”构建可执行文件。

运行添加数据的命令会引发如下错误:pyinstaller: 错误: 无法识别的参数: --add-data C:\Users<>... --add-data: C:\Users<>...

def make_executable(main_script: str, files_to_add: List[str], target_location: str = None,
name: str = 'app', single_file: bool = True) -> None:
"""
Creating an executable file out of the provided parameters.
:param main_script: Main script of the application.
:param files_to_add: A list of files that are crucial to the project.
:param target_location: Where to store the executable file.
:param name: Name of the executable file.
:param single_file: Determine whether a single file or a directory is to be created.
:return: None.
"""
args = [main_script, f'--name {name}']
if target_location is not None:
args.append(f'--distpath {target_location}')
if single_file:
args.append('--onefile')
for file in files_to_add:
args.append(f'--add-data {file}')
PyInstaller.__main__.run(args)

我也试过用类似的东西

  • --添加数据 C:\Users<>\xyz;. -- 添加数据 C:\Users<>\abc;.
  • --添加数据“C:\Users<>\xyz;.” -- 添加数据 "C:\Users<>\abc;."

注意:每个反斜杠都被转义了。

我该怎么做才能添加所需的数据?在此问题上的任何帮助表示赞赏!

最佳答案

根据 PyInstaller docs :

--add-data <SRC;DEST or SRC:DEST>
Additional non-binary files or folders to be added to the executable. The path separator is platform specific, os.pathsep (which is ; on Windows and : on most unix systems) is used. This option can be used multiple times.

您还需要拆分列表中的标志和参数。像这样:

if target_location is not None:
args.append("--dispath")
args.append(target_location)
if single_file:
args.append('--onefile')
for file in files_to_add:
args.append("--add-data")
args.append(f'{file};{some destination}')

关于python - PyInstaller -- 从脚本添加数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72315624/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com