PyInstaller -- 从脚本添加数据

PyInstaller --add-data from script

我正在尝试从我的 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)

我也试过使用类似

的东西

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

如何添加所需的数据? 在此问题上的任何帮助表示赞赏!

根据 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}')