简体   繁体   English

ModuleNotFoundError: 没有名为“my_app”的模块,应用程序已经在 INSTALLED_APPS 中

[英]ModuleNotFoundError: No module named 'my_app’, app already in INSTALLED_APPS

I'm trying to deploy my Django app through Heroku but I'm getting a ModuleNotFound error after running a production environment with gunicorn wsgi path.我正在尝试通过 Heroku 部署我的 Django 应用程序,但是在使用 gunicorn wsgi 路径运行生产环境后出现ModuleNotFound error My app is included in settings.py and it was working fine while in the development environment.我的应用程序包含在 settings.py 中,并且在开发环境中运行良好。 But now I'm getting errors for deployment.但是现在我遇到了部署错误。 I have problems with how my project is structured, thus Procfile does not leave in the same directory as manage.py, and I believe this could be the issue.我的项目结构有问题,因此Procfile与 manage.py 不在同一目录中,我相信这可能是问题所在。 Any hint or help is more than appreciated.任何提示或帮助都非常感谢。

Directory structure目录结构

 >FINALPROJECT(root)
    > .vscode
    > project5
        > brainSkills
           > migrations
           > static
           > templates
           apps.py
           models.py
           urls.py
           views.py
        > project5
           _init_.py
           settings.py
           wsgi.py
        _init_.py
        manage.py
    > venv
    .env
    .gitignore
    Procfile
    README.md
    requirements.txt

Procfile配置文件

web: gunicorn project5.project5.wsgi

wsgi.py wsgi.py

import os
 
from django.core.wsgi import get_wsgi_application
 
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project5.project5.settings')
 
application = get_wsgi_application()

setting.py设置.py

import os
from pathlib import Path
from dotenv import load_dotenv

INSTALLED_APPS = [
   'brainSkills',
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
]

ROOT_URLCONF = 'project5.urls'

WSGI_APPLICATION = 'project5.wsgi.application'

Error after gunicorn project5.project5.wsgi or Heroku local gunicorn project5.project5.wsgiHeroku localgunicorn project5.project5.wsgi

5:32:28 PM web.1 |    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
5:32:28 PM web.1 |      return _bootstrap._gcd_import(name[level:], package, level)
5:32:28 PM web.1 |    File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
5:32:28 PM web.1 |    File "<frozen importlib._bootstrap>", line 991, in _find_and_load
5:32:28 PM web.1 |    File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
5:32:28 PM web.1 |  ModuleNotFoundError: No module named 'brainSkills'
5:32:28 PM web.1 |  [2020-10-12 21:32:28 +0000] [57691] [INFO] Worker exiting (pid: 57691)
5:32:28 PM web.1 |  [2020-10-12 17:32:28 -0400] [57689] [INFO] Shutting down: Master
5:32:28 PM web.1 |  [2020-10-12 17:32:28 -0400] [57689] [INFO] Reason: Worker failed to boot.
[DONE] Killing all processes with signal  SIGINT
5:32:28 PM web.1 Exited with exit code null

Try changing the way you are adding it to INSTALLED_APPS :尝试更改将其添加到INSTALLED_APPS

INSTALLED_APPS = [
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'brainSkills.apps.BrainSkillsConfig',
]

More about this here .更多关于这里 While doing the research for this question I learned that prior to Django 1.7 your approach would be correct if you also used default_app_config = 'brainSkills.apps.BrainSkillsConfig' in your app's __init__.py .在对这个问题进行研究时,我了解到在 Django 1.7 之前,如果您还在应用的__init__.py使用了default_app_config = 'brainSkills.apps.BrainSkillsConfig'那么您的方法是正确的。 However Django now recommends the approach I show above.但是 Django 现在推荐我上面展示的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ModuleNotFoundError: 没有名为“my_app”的模块 - ModuleNotFoundError: No module named 'my_app' ModuleNotFoundError:进行迁移时没有名为“my_app”的模块 - ModuleNotFoundError: No module named 'my_app' while making migrations Heroku Django ModuleNotFoundError:没有名为“my_app”的模块 - Heroku Django ModuleNotFoundError: No module named 'my_app' ImportError:Django Oscar中没有名为应用的模块错误-在INSTALLED_APPS中包含应用 - ImportError: No module named apps error in Django Oscar - while including an app in INSTALLED_APPS ImportError:添加到INSTALLED_APPS后没有名为“ first_app”的模块 - ImportError: No module named 'first_app' after adding to INSTALLED_APPS 无法从终端运行 Flask,“没有名为‘my_app’的模块” - Unable to run Flask from Terminal, “No module named 'my_app’” 在INSTALLED_APPS中包含应用程序的两种方法 - Two ways of including an app in INSTALLED_APPS ModuleNotFoundError:没有名为“六”的模块,六已安装 - ModuleNotFoundError: No module named 'six' , Six is already installed ModuleNotFoundError:没有名为“msgpack”的模块,但已经安装了 msgpack - ModuleNotFoundError: No module named 'msgpack', but msgpack is already installed makemigrations无法在INSTALLED_APPS中找到应用 - makemigrations not able to find app within INSTALLED_APPS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM