Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用pyinstaller添加Json文件_Python_Json_Pyinstaller - Fatal编程技术网

Python 使用pyinstaller添加Json文件

Python 使用pyinstaller添加Json文件,python,json,pyinstaller,Python,Json,Pyinstaller,我正在用python编写一个小的文本冒险游戏,我正在json文件中编写故事内容。我想创建一个可执行文件与我的朋友共享游戏,所以我使用pyinstaller创建.exe,但我需要它包含json文件 我试着用这个命令 pyinstaller --onefile --add-data 'story.json;.' main.py 它不会给出任何错误,并且将该文件包含在.spec中 a = Analysis(['main.py'], pathex=['D:\\python-proje

我正在用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文件并阅读故事