使用pyinstaller添加Json文件

时间:2020-08-30 01:09:26

标签: python json pyinstaller

我正在用python编写一个小型的文字冒险游戏,并将故事内容写在json文件中。我想创建一个可执行文件与朋友共享游戏,因此我使用pyinstaller创建.exe,但是我需要它包含json文件。

我尝试使用此命令

pyinstaller --onefile --add-data 'story.json;.' main.py

不会出现任何错误,并且将文件包含在.spec中就可以了

a = Analysis(['main.py'],
         pathex=['D:\\python-projects\\text-adventure-game'],
         binaries=[],
         datas=[('story.json', '.')],

但是当我尝试运行.exe时,它说

FileNotFoundError: [Errno 2] No such file or directory: 'story.json'

我知道,如果将json文件与.exe放在同一文件夹中,它将起作用,但我不想这样做,因为那样他们就可以打开json文件并读取故事

0 个答案:

没有答案