首页 > 解决方案 > FileNotFoundError 即使文件存在

问题描述

因此,我正在使用 Python 3 和 Ursina 游戏引擎制作游戏,并在尝试加载文件时不断收到此错误:

Traceback (most recent call last):
  File "main.py", line 5, in <module>
    from src.menu import *
  File "/home/mysteriousk/Desktop/moni moni moni/src/menu.py", line 4, in <module>
    with open('../assets/database/database.json','r') as E:
FileNotFoundError: [Errno 2] No such file or directory: '../assets/database/database.json'

我正在执行的文件是main.py and the file I am importing is in the folder src and is named menu.py`。加载我的文件的代码:

with open('../assets/database/database.json','r') as E:
    stuffs = json.load(E)

该文件显然存在于目录 assets/database 中。请让我知道有什么问题,感谢您的帮助。

标签: pythonjsonpython-3.xfile-not-foundpython-3.9

解决方案


推荐阅读