使用 pyinstaller 包含多个数据文件

jqw*_*wha 5 pyinstaller

我需要在 pyinstaller“onefile”可执行文件中包含一个 DLL 和一个文本文件。我可以只添加 DLL,但如果我尝试指定这两个文件,pyinstaller 会抱怨。我宁愿使用命令行选项(而不是规范文件)-多个文件的正确格式是什么?

http://pyinstaller.readthedocs.io/en/stable/spec-files.html#adding-data-files

http://pyinstaller.readthedocs.io/en/stable/usage.html#options-group-what-to-bundle-where-to-search

尝试了一些东西,例如 pyinstaller: error: argument --add-data: invalid add_data_or_binary value: '/C/path1/my.dll;/c/path2/my.txt;.'

jqw*_*wha 7

答案在https://media.readthedocs.org/pdf/pyinstaller/cross-compiling/pyinstaller.pdf 中,这表明我可以多次使用 --add-data 选项!


Nim*_*avi 7

我不知道命令行需要哪种语法,但您可以编辑生成的规范以包含数据的路径,其中数据是元组列表。

datas = [('/path/to/file', '/path/in/bundle').
          (...) ]
Run Code Online (Sandbox Code Playgroud)

所以规范可能如下所示:

a = Analysis(['Frequency_Analysis_DataInput_Animation_cge.py'],
             pathex=['C:\\Users\\mousavin\\Documents\\Analysis'],
             binaries=[],
             datas=[('/path/file1', '.'), (/path/file2, '.')],
...
Run Code Online (Sandbox Code Playgroud)

然后再次构建

pyinstaller script.spec
Run Code Online (Sandbox Code Playgroud)