1

When I try to access my app after deployment it results in an H10 error. It seems to reference favicon in the log and also says that Django isn't installed (I have run pip3 list in my venv and it appears to be there, it is also in requirements.txt).

Here is the log:

2022-01-14T04:51:29.245939+00:00 heroku[web.1]: Starting process with command `python manage.py runserver 0.0.0.0:42836`
2022-01-14T04:51:30.238629+00:00 app[web.1]: Traceback (most recent call last):
2022-01-14T04:51:30.238658+00:00 app[web.1]: File "manage.py", line 11, in main
2022-01-14T04:51:30.238659+00:00 app[web.1]: from django.core.management import execute_from_command_line
2022-01-14T04:51:30.238659+00:00 app[web.1]: ModuleNotFoundError: No module named 'django'
2022-01-14T04:51:30.238660+00:00 app[web.1]: 
2022-01-14T04:51:30.238660+00:00 app[web.1]: The above exception was the direct cause of the following exception:
2022-01-14T04:51:30.238660+00:00 app[web.1]: 
2022-01-14T04:51:30.238660+00:00 app[web.1]: Traceback (most recent call last):
2022-01-14T04:51:30.238661+00:00 app[web.1]: File "manage.py", line 22, in <module>
2022-01-14T04:51:30.238661+00:00 app[web.1]: main()
2022-01-14T04:51:30.238661+00:00 app[web.1]: File "manage.py", line 13, in main
2022-01-14T04:51:30.238662+00:00 app[web.1]: raise ImportError(
2022-01-14T04:51:30.238672+00:00 app[web.1]: ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
2022-01-14T04:51:30.414522+00:00 heroku[web.1]: Process exited with status 1
2022-01-14T04:51:30.500903+00:00 heroku[web.1]: State changed from starting to crashed

This is also in the log:

2022-01-14T08:48:31.449379+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=vygrapp.herokuapp.com request_id=dfd73435-79ec-4925-9206-f40eabededfd fwd="61.68.159.52" dyno= connect= service= status=503 bytes= protocol=https
2022-01-14T08:48:31.770207+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=vygrapp.herokuapp.com request_id=6bdac394-8932-492b-b0b2-f9f4785a23de fwd="61.68.159.52" dyno= connect= service= status=503 bytes= protocol=https

Here is the contents of my Procfile:

web: python manage.py runserver 0.0.0.0:$PORT

After updating requirements.txt I get this issue:

remote: -----> $ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "/tmp/build_4a60c6e6/manage.py", line 22, in <module>
remote:            main()
remote:          File "/tmp/build_4a60c6e6/manage.py", line 18, in main
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 425, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute
remote:            django.setup()
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
remote:            apps.populate(settings.INSTALLED_APPS)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate
remote:            app_config.import_models()
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/apps/config.py", line 300, in import_models
remote:            self.models_module = import_module(models_module_name)
remote:          File "/app/.heroku/python/lib/python3.9/importlib/__init__.py", line 127, in import_module
remote:            return _bootstrap._gcd_import(name[level:], package, level)
remote:          File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
remote:          File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
remote:          File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
remote:          File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
remote:          File "<frozen importlib._bootstrap_external>", line 850, in exec_module
remote:          File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/auth/models.py", line 3, in <module>
remote:            from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
remote:            class AbstractBaseUser(models.Model):
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/db/models/base.py", line 122, in __new__
remote:            new_class.add_to_class('_meta', Options(meta, app_label))
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/db/models/base.py", line 326, in add_to_class
remote:            value.contribute_to_class(cls, name)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/db/models/options.py", line 207, in contribute_to_class
remote:            self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/utils/connection.py", line 15, in __getattr__
remote:            return getattr(self._connections[self._alias], item)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/utils/connection.py", line 62, in __getitem__
remote:            conn = self.create_connection(alias)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/db/utils.py", line 204, in create_connection
remote:            backend = load_backend(db['ENGINE'])
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/db/utils.py", line 111, in load_backend
remote:            return import_module('%s.base' % backend_name)
remote:          File "/app/.heroku/python/lib/python3.9/importlib/__init__.py", line 127, in import_module
remote:            return _bootstrap._gcd_import(name[level:], package, level)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 6, in <module>
remote:            from .features import DatabaseFeatures
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/backends/postgis/features.py", line 1, in <module>
remote:            from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/backends/base/features.py", line 3, in <module>
remote:            from django.contrib.gis.db import models
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module>
remote:            import django.contrib.gis.db.models.functions  # NOQA
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/models/functions.py", line 3, in <module>
remote:            from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module>
remote:            from django.contrib.gis import forms, gdal
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
remote:            from .fields import (  # NOQA
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/forms/fields.py", line 2, in <module>
remote:            from django.contrib.gis.gdal import GDALException
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
remote:            from django.contrib.gis.gdal.datasource import DataSource
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/gdal/datasource.py", line 40, in <module>
remote:            from django.contrib.gis.gdal.driver import Driver
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/gdal/driver.py", line 5, in <module>
remote:            from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
remote:            from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/gdal/libgdal.py", line 53, in <module>
remote:            lgdal = CDLL(lib_path)
remote:          File "/app/.heroku/python/lib/python3.9/ctypes/__init__.py", line 374, in __init__
remote:            self._handle = _dlopen(self._name, mode)
remote:        OSError: /opt/homebrew/opt/gdal/lib/libgdal.dylib: cannot open shared object file: No such file or directory
remote: 
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.
remote: 
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote: 
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote: 
remote:        https://devcenter.heroku.com/articles/django-assets
remote:  !     Push rejected, failed to compile Python app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !       Push rejected to vygrapp.
deadant88
  • 920
  • 9
  • 24

1 Answers1

1

Your Procfile is not a valid one

You have to change

web: python manage.py runserver 0.0.0.0:$PORT

to

web: gunicorn your_django_progect_name.wsgi:application --log-file - --log-level debug

Be sure to add gunicorn to your requirements.txt file as well. read this

Sumithran
  • 6,217
  • 4
  • 40
  • 54
  • Hi. How do i do this? – deadant88 Jan 14 '22 at 06:22
  • see this https://devcenter.heroku.com/articles/django-app-configuration – Sumithran Jan 14 '22 at 06:24
  • Thanks, I edited procfile as per your advice but still crashes. I have included the contents of my requirements.txt in OP and you can see that ``Django`` is in their (as is ``gunicorn`` - the other issue is the favicon.ico ``503`` error (in OP) - could it be related to this? – deadant88 Jan 14 '22 at 08:53
  • Can you share your new deploy log? – Sumithran Jan 14 '22 at 09:09
  • Yes I also updated by requirements.txt file as per [this](https://stackoverflow.com/a/62279745/13831283). The new deploy log is added to OP – deadant88 Jan 14 '22 at 10:01
  • Try disabling collect static https://stackoverflow.com/questions/36665889/collectstatic-error-while-deploying-django-app-to-heroku – Sumithran Jan 14 '22 at 11:00
  • Looks like it's an issue with GDAL dependency, I can't figure it out though. – deadant88 Jan 14 '22 at 11:04
  • Yes there is issue with GDAL too.. you have to fix the collects static issue to deploy this app – Sumithran Jan 14 '22 at 11:05
  • I've added this [buildpack](https://elements.heroku.com/buildpacks/heroku/heroku-geo-buildpack) and added `GDAL` to my requirements.txt but get ``ERROR: Command errored out with exit status 1:`` when it deploying tries to install ``GDAL`` – deadant88 Jan 14 '22 at 11:07
  • 1
    You may ask another question, BTW hope this answers the originally posted issue. – Sumithran Jan 14 '22 at 11:19
  • 1
    Yes thanks - fixed one problem now `x` more to go for me :) – deadant88 Jan 14 '22 at 11:29
  • Yeah just post a new question, someone might answer it! – Sumithran Jan 14 '22 at 11:43