调用heroku运行“otree resetdb”时发生FileNotFoundError

2024-09-30 00:24:30 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我收到了一个FileNotFoundError: [Errno 2] No such file or directory error,我真的不知道该怎么办,因为文件肯定在那里。当我尝试在命令heroku run "otree resetdb"之后使用heroku和git部署oTree实验时,会发生错误。操作系统是Windows10

完整错误消息:

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'

我还尝试了一个带有普通斜杠和双反斜杠的代码版本,但仍然收到了相同的错误。接下来,我尝试使用pathlib中的路径重写models.py中的路径,如下所示:

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上的部署。欢迎任何建议,非常感谢

最好的, 丽娜


Tags: djangoinpyimportappherokumodelslib

热门问题