所以我收到了一个FileNotFoundError: [Errno 2] No such file or directory error
,老实说,我不知道该怎么做,因为文件肯定在那里。当我尝试在命令之后使用 heroku 和 git 部署 oTree 实验时,会发生错误heroku run "otree resetdb"
。操作系统为 Windows 10。
完整的错误信息:
Running otree resetdb on ⬢ otreeexperimentna... up, run.5607 (Free)
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.7/site-packages/otree_startup/__init__.py", line 227, in do_django_setup
django.setup()
File "/app/.heroku/python/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/experimentMusic/models.py", line 21, in <module>
class Constants(BaseConstants):
File "/app/experimentMusic/models.py", line 26, in Constants
with open('D:\Experiment\oTreeproject\oTreeonlineshop-master\shop\oTree\experimentMusic\products.json', 'r', encoding='utf-8') as jsonfile:
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\Experiment\\oTreeproject\\oTreeonlineshop-master\\shop\\oTree\\experimentMusic\\products.json'
我还尝试了带有普通斜杠和双反斜杠的代码版本,但仍然收到相同的错误。接下来,我尝试models.py
使用 pathlib 中的 Path 重写路径,如下所示:
from pathlib import Path
with open(Path('D:/Experiment/oTreeproject/oTreeonlineshop-master/shop/oTree/experimentMusic/products.json'), 'r', encoding='utf-8') as jsonfile:
data=jsonfile.read()
shoppinglist = json.loads(data)
它也不起作用,并带有类似的错误消息。
可能是什么问题呢?文件 products.json 在那里并且不是空的,所以我不知道为什么它不起作用。我还尝试在我的笔记本电脑上运行这个实验,它工作得很好,所以我猜问题是在 heroku 上的部署。欢迎任何建议,非常感谢!
最好的,丽娜