1

After deploying a test site to heroku, it shows an Application Error:

enter image description here

Heroku Log:

2021-06-25T13:20:42.143490+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-06-25T13:20:42.143491+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-06-25T13:20:42.143492+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-06-25T13:20:42.143492+00:00 app[web.1]: self.callable = self.load()
2021-06-25T13:20:42.143492+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-06-25T13:20:42.143493+00:00 app[web.1]: return self.load_wsgiapp()
2021-06-25T13:20:42.143493+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-06-25T13:20:42.143494+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-06-25T13:20:42.143494+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
2021-06-25T13:20:42.143494+00:00 app[web.1]: mod = importlib.import_module(module)
2021-06-25T13:20:42.143495+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2021-06-25T13:20:42.143495+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-06-25T13:20:42.143496+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-06-25T13:20:42.143496+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-06-25T13:20:42.143496+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2021-06-25T13:20:42.143497+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2021-06-25T13:20:42.143497+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 848, in exec_module
2021-06-25T13:20:42.143498+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-06-25T13:20:42.143498+00:00 app[web.1]: File "/app/config/wsgi.py", line 12, in <module>
2021-06-25T13:20:42.143498+00:00 app[web.1]: from django.core.wsgi import get_wsgi_application
2021-06-25T13:20:42.143499+00:00 app[web.1]: ModuleNotFoundError: No module named 'django'
2021-06-25T13:20:42.144378+00:00 app[web.1]: [2021-06-25 13:20:42 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-06-25T13:20:42.184157+00:00 app[web.1]: [2021-06-25 13:20:42 +0000] [9] [INFO] Booting worker with pid: 9
2021-06-25T13:20:42.220213+00:00 app[web.1]: [2021-06-25 13:20:42 +0000] [9] [ERROR] Exception in worker process
2021-06-25T13:20:42.220214+00:00 app[web.1]: Traceback (most recent call last):
2021-06-25T13:20:42.220215+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2021-06-25T13:20:42.220216+00:00 app[web.1]: worker.init_process()
2021-06-25T13:20:42.220216+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
2021-06-25T13:20:42.220216+00:00 app[web.1]: self.load_wsgi()
2021-06-25T13:20:42.220217+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-06-25T13:20:42.220217+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-06-25T13:20:42.220218+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-06-25T13:20:42.220218+00:00 app[web.1]: self.callable = self.load()
2021-06-25T13:20:42.220219+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-06-25T13:20:42.220219+00:00 app[web.1]: return self.load_wsgiapp()
2021-06-25T13:20:42.220220+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-06-25T13:20:42.220220+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-06-25T13:20:42.220220+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
2021-06-25T13:20:42.220221+00:00 app[web.1]: mod = importlib.import_module(module)
2021-06-25T13:20:42.220221+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2021-06-25T13:20:42.220222+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-06-25T13:20:42.220222+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-06-25T13:20:42.220222+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-06-25T13:20:42.220223+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2021-06-25T13:20:42.220223+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2021-06-25T13:20:42.220224+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 848, in exec_module
2021-06-25T13:20:42.220224+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-06-25T13:20:42.220224+00:00 app[web.1]: File "/app/config/wsgi.py", line 12, in <module>
2021-06-25T13:20:42.220225+00:00 app[web.1]: from django.core.wsgi import get_wsgi_application
2021-06-25T13:20:42.220225+00:00 app[web.1]: ModuleNotFoundError: No module named 'django'
2021-06-25T13:20:42.222244+00:00 app[web.1]: [2021-06-25 13:20:42 +0000] [9] [INFO] Worker exiting (pid: 9)
2021-06-25T13:20:42.237399+00:00 app[web.1]: [2021-06-25 13:20:42 +0000] [4] [WARNING] Worker with pid 9 was terminated due to signal 15
2021-06-25T13:20:42.341186+00:00 app[web.1]: [2021-06-25 13:20:42 +0000] [4] [INFO] Shutting down: Master
2021-06-25T13:20:42.382466+00:00 app[web.1]: [2021-06-25 13:20:42 +0000] [4] [INFO] Reason: Worker failed to boot.
2021-06-25T13:20:42.762358+00:00 heroku[web.1]: Process exited with status 3
2021-06-25T13:20:42.868448+00:00 heroku[web.1]: State changed from starting to crashed
2021-06-25T13:20:42.872437+00:00 heroku[web.1]: State changed from crashed to starting
2021-06-25T13:20:50.974740+00:00 heroku[web.1]: Starting process with command `gunicorn config.wsgi --log-file -`
2021-06-25T13:20:53.577634+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [4] [INFO] Starting gunicorn 20.1.0
2021-06-25T13:20:53.578269+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [4] [INFO] Listening at: http://0.0.0.0:13141 (4)
2021-06-25T13:20:53.578415+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [4] [INFO] Using worker: sync
2021-06-25T13:20:53.583477+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [8] [INFO] Booting worker with pid: 8
2021-06-25T13:20:53.588859+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [8] [ERROR] Exception in worker process
2021-06-25T13:20:53.588860+00:00 app[web.1]: Traceback (most recent call last):
2021-06-25T13:20:53.588860+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2021-06-25T13:20:53.588861+00:00 app[web.1]: worker.init_process()
2021-06-25T13:20:53.588861+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
2021-06-25T13:20:53.588861+00:00 app[web.1]: self.load_wsgi()
2021-06-25T13:20:53.588861+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-06-25T13:20:53.588862+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-06-25T13:20:53.588862+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-06-25T13:20:53.588862+00:00 app[web.1]: self.callable = self.load()
2021-06-25T13:20:53.588862+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-06-25T13:20:53.588863+00:00 app[web.1]: return self.load_wsgiapp()
2021-06-25T13:20:53.588863+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-06-25T13:20:53.588863+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-06-25T13:20:53.588864+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
2021-06-25T13:20:53.588864+00:00 app[web.1]: mod = importlib.import_module(module)
2021-06-25T13:20:53.588864+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2021-06-25T13:20:53.588864+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-06-25T13:20:53.588865+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-06-25T13:20:53.588865+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-06-25T13:20:53.588865+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2021-06-25T13:20:53.588865+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2021-06-25T13:20:53.588865+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 848, in exec_module
2021-06-25T13:20:53.588866+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-06-25T13:20:53.588866+00:00 app[web.1]: File "/app/config/wsgi.py", line 12, in <module>
2021-06-25T13:20:53.588866+00:00 app[web.1]: from django.core.wsgi import get_wsgi_application
2021-06-25T13:20:53.588866+00:00 app[web.1]: ModuleNotFoundError: No module named 'django'
2021-06-25T13:20:53.588953+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-06-25T13:20:53.613376+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [4] [INFO] Shutting down: Master
2021-06-25T13:20:53.613444+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [4] [INFO] Reason: Worker failed to boot.
2021-06-25T13:20:53.666415+00:00 heroku[web.1]: Process exited with status 3
2021-06-25T13:20:53.736085+00:00 heroku[web.1]: State changed from starting to crashed
2021-06-25T13:21:03.827606+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=infinite-lake-64780.herokuapp.com request_id
=ebdb0566-934d-42f3-8406-3c22ad946ffe fwd="91.23.54.245" dyno= connect= service= status=503 bytes= protocol=https
2021-06-25T13:21:04.056665+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=infinite-lake-64780.herokuapp.com
 request_id=f39bf025-1373-4119-8d11-bad44e3a7a1d fwd="91.23.54.245" dyno= connect= service= status=503 bytes= protocol=https
2021-06-25T13:25:13.778941+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=infinite-lake-64780.herokuapp.com request_id
=cf9fc6eb-e3e5-4028-aec6-b06ebd759654 fwd="91.23.54.245" dyno= connect= service= status=503 bytes= protocol=https
2021-06-25T13:25:14.062569+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=infinite-lake-64780.herokuapp.com
 request_id=244089c9-a74f-4fbb-a4cf-88efd26bf187 fwd="91.23.54.245" dyno= connect= service= status=503 bytes= protocol=https
2021-06-25T13:29:24.973091+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=infinite-lake-64780.herokuapp.com request_id
=161fe80f-f695-4eff-873f-a99576f5eb6b fwd="91.23.54.245" dyno= connect= service= status=503 bytes= protocol=https
2021-06-25T13:29:25.244494+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=infinite-lake-64780.herokuapp.com
 request_id=702bd951-0a20-47c3-9c2f-8bbefc77379f fwd="91.23.54.245" dyno= connect= service= status=503 bytes= protocol=https

This seems to be the problem:

2021-06-25T13:20:53.588866+00:00 app[web.1]: ModuleNotFoundError: No module named 'django'

This is the root dir:

enter image description here

config/settings.py:

"""
Django settings for config project.

Generated by 'django-admin startproject' using Django 3.2.4.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'security__key'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']


# Application definition

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

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'config.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [str(BASE_DIR.joinpath('templates'))],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'config.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

Procfile:

web: gunicorn config.wsgi --log-file -

Pipfile:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
gunicorn = "*"

[dev-packages]

[requires]
python_version = "3.8"

requirements.txt:

gunicorn

runtime.txt:

python-3.8.10
torek
  • 448,244
  • 59
  • 642
  • 775
Artur Müller Romanov
  • 4,417
  • 10
  • 73
  • 132

2 Answers2

0

The problem is that Django is not in your requirements.txt file. You have to include all modules you use in your requirements.txt file.

To fix this, change your requirements.txt file to include Django(and any other modules you use)

Your requirements.txt file should look like this(if you don't have any other modules):

django
gunicorn

If you still get the same error, delete your Pipfile, and make sure you have staged, committed, and pushed your changes to Heroku through git.

To stage, commit, and push, do the following in the command line(make sure you are in the directory of your app)

To stage your changes:

git add .

To commit your changes:

git commit -m 'Updated requirements.txt'

To push your changes to Heroku:

git push heroku master
HackDolphin
  • 166
  • 11
  • I followed your instructions, I added `django` into `requirements.txt`, commited with `git add` and `git commit` and pushed to `heroku` but I am still getting the same error. – Artur Müller Romanov Jun 26 '21 at 09:57
0

Thanks to ENDESSA's comment, I was able to solve the issue. I found the solution in requirements.txt vs Pipfile in heroku flask webapp deployment?.

There seems to be a problem with Pipfile and requirements.txt. When you setup pipenv, it creates Pipfile and ignores requirements.txt. My problem was that I setup venv in Pycharm AND installed pipenv, which lead to errors. After I deleted Pipfile my test site worked correctly.

I also had to set heroku config:set DISABLE_COLLECTSTATIC=1 and I'm not entirely sure if heroku ps:scale web=1 was necessary as well.

Anyhoo, thanks alot

Artur Müller Romanov
  • 4,417
  • 10
  • 73
  • 132