0

I am trying to deploy a webapp using Heroku and it get deployed but it gives internal server error when I try to open it. The complete log as from heroku logs -t is as follows:

2021-10-29T09:03:55.451439+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/exception.py", line 152, in handle_uncaught_exception
2021-10-29T09:03:55.451439+00:00 app[web.1]: callback = resolver.resolve_error_handler(500)
2021-10-29T09:03:55.451442+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/urls/resolvers.py", line 611, in resolve_error_handler
2021-10-29T09:03:55.451442+00:00 app[web.1]: callback = getattr(self.urlconf_module, 'handler%s' % view_type, None)
2021-10-29T09:03:55.451442+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
2021-10-29T09:03:55.451443+00:00 app[web.1]: res = instance.__dict__[self.name] = self.func(instance)
2021-10-29T09:03:55.451443+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/urls/resolvers.py", line 591, in urlconf_module
2021-10-29T09:03:55.451443+00:00 app[web.1]: return import_module(self.urlconf_name)
2021-10-29T09:03:55.451444+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2021-10-29T09:03:55.451444+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-10-29T09:03:55.451444+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-10-29T09:03:55.451444+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-10-29T09:03:55.451444+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2021-10-29T09:03:55.451444+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2021-10-29T09:03:55.451444+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 783, in exec_module
2021-10-29T09:03:55.451444+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-10-29T09:03:55.451445+00:00 app[web.1]: File "/app/server/urls.py", line 7, in <module>
2021-10-29T09:03:55.451445+00:00 app[web.1]: path('apis/',include('apis.urls',namespace='apis')),
2021-10-29T09:03:55.451445+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
2021-10-29T09:03:55.451445+00:00 app[web.1]: urlconf_module = import_module(urlconf_module)
2021-10-29T09:03:55.451445+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2021-10-29T09:03:55.451446+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)2021-10-29T09:03:55.451446+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-10-29T09:03:55.451446+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-10-29T09:03:55.451446+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2021-10-29T09:03:55.451446+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2021-10-29T09:03:55.451446+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 783, in exec_module
2021-10-29T09:03:55.451447+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-10-29T09:03:55.451447+00:00 app[web.1]: File "/app/apis/urls.py", line 2, in <module>
2021-10-29T09:03:55.451447+00:00 app[web.1]: from apis import views
2021-10-29T09:03:55.451447+00:00 app[web.1]: File "/app/apis/views.py", line 4, in <module>
2021-10-29T09:03:55.451447+00:00 app[web.1]: from apis import model
2021-10-29T09:03:55.451447+00:00 app[web.1]: File "/app/apis/model.py", line 9, in <module>
2021-10-29T09:03:55.451448+00:00 app[web.1]: import PySimpleGUI as sg
2021-10-29T09:03:55.451448+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/PySimpleGUI/__init__.py", line 2, in <module>
2021-10-29T09:03:55.451448+00:00 app[web.1]: from .PySimpleGUI import *
2021-10-29T09:03:55.451448+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 117, in <module>
2021-10-29T09:03:55.451448+00:00 app[web.1]: import tkinter as tk
2021-10-29T09:03:55.451448+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/tkinter/__init__.py", line 36, in <module>
2021-10-29T09:03:55.451448+00:00 app[web.1]: import _tkinter # If this fails your Python may not be configured for Tk
2021-10-29T09:03:55.451449+00:00 app[web.1]: ModuleNotFoundError: No module named '_tkinter'
2021-10-29T09:03:55.451449+00:00 app[web.1]:
2021-10-29T09:03:55.451454+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2021-10-29T09:03:55.451454+00:00 app[web.1]:
2021-10-29T09:03:55.451455+00:00 app[web.1]: Traceback (most recent call last):
2021-10-29T09:03:55.451455+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 136, in handle
2021-10-29T09:03:55.451455+00:00 app[web.1]: self.handle_request(listener, req, client, addr)
2021-10-29T09:03:55.451455+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 179, in handle_request
2021-10-29T09:03:55.451455+00:00 app[web.1]: respiter = self.wsgi(environ, resp.start_response)
2021-10-29T09:03:55.451456+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/wsgi.py", line 133, in __call__
2021-10-29T09:03:55.451456+00:00 app[web.1]: response = self.get_response(request)
2021-10-29T09:03:55.451456+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/base.py", line 130, in get_response
2021-10-29T09:03:55.451456+00:00 app[web.1]: response = self._middleware_chain(request)
2021-10-29T09:03:55.451462+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/exception.py", line 49, in inner
2021-10-29T09:03:55.451462+00:00 app[web.1]: response = response_for_exception(request, exc)
2021-10-29T09:03:55.451462+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/exception.py", line 114, in response_for_exception
2021-10-29T09:03:55.451462+00:00 app[web.1]: response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
2021-10-29T09:03:55.451462+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/exception.py", line 152, in handle_uncaught_exception
2021-10-29T09:03:55.451463+00:00 app[web.1]: callback = resolver.resolve_error_handler(500)
2021-10-29T09:03:55.451463+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/urls/resolvers.py", line 611, in resolve_error_handler
2021-10-29T09:03:55.451465+00:00 app[web.1]: callback = getattr(self.urlconf_module, 'handler%s' % view_type, None)
2021-10-29T09:03:55.451465+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
2021-10-29T09:03:55.451465+00:00 app[web.1]: res = instance.__dict__[self.name] = self.func(instance)
2021-10-29T09:03:55.451465+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/urls/resolvers.py", line 591, in urlconf_module
2021-10-29T09:03:55.451466+00:00 app[web.1]: return import_module(self.urlconf_name)
2021-10-29T09:03:55.451466+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2021-10-29T09:03:55.451466+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-10-29T09:03:55.451466+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-10-29T09:03:55.451466+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-10-29T09:03:55.451466+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2021-10-29T09:03:55.451467+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2021-10-29T09:03:55.451467+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 783, in exec_module
2021-10-29T09:03:55.451467+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-10-29T09:03:55.451467+00:00 app[web.1]: File "/app/server/urls.py", line 7, in <module>
2021-10-29T09:03:55.451467+00:00 app[web.1]: path('apis/',include('apis.urls',namespace='apis')),
2021-10-29T09:03:55.451467+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
2021-10-29T09:03:55.451467+00:00 app[web.1]: urlconf_module = import_module(urlconf_module)
2021-10-29T09:03:55.451468+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2021-10-29T09:03:55.451468+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-10-29T09:03:55.451468+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-10-29T09:03:55.451468+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-10-29T09:03:55.451468+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2021-10-29T09:03:55.451469+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2021-10-29T09:03:55.451469+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 783, in exec_module
2021-10-29T09:03:55.451469+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-10-29T09:03:55.451469+00:00 app[web.1]: File "/app/apis/urls.py", line 2, in <module>
2021-10-29T09:03:55.451469+00:00 app[web.1]: from apis import views
2021-10-29T09:03:55.451470+00:00 app[web.1]: File "/app/apis/views.py", line 4, in <module>
2021-10-29T09:03:55.451470+00:00 app[web.1]: from apis import model
2021-10-29T09:03:55.451470+00:00 app[web.1]: File "/app/apis/model.py", line 9, in <module>
2021-10-29T09:03:55.451470+00:00 app[web.1]: import PySimpleGUI as sg
2021-10-29T09:03:55.451471+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/PySimpleGUI/__init__.py", line 2, in <module>
2021-10-29T09:03:55.451471+00:00 app[web.1]: from .PySimpleGUI import *
2021-10-29T09:03:55.451471+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 117, in <module>
2021-10-29T09:03:55.451471+00:00 app[web.1]: import tkinter as tk
2021-10-29T09:03:55.451471+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/tkinter/__init__.py", line 36, in <module>
2021-10-29T09:03:55.451471+00:00 app[web.1]: import _tkinter # If this fails your Python may not be configured for Tk
2021-10-29T09:03:55.451472+00:00 app[web.1]: ModuleNotFoundError: No module named '_tkinter'
2021-10-29T09:03:55.451616+00:00 app[web.1]: 10.1.91.66 - - [29/Oct/2021:09:03:55 +0000] "GET /favicon.ico HTTP/1.1" 500 0 "-" "-"
2021-10-29T09:03:55.453961+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=risk-category.herokuapp.com request_id=37f18c7a-c27e-4385-afd7-8efb39882b2f fwd="49.36.187.226" dyno=web.1 connect=0ms service=44ms status=500 bytes=244 protocol=https

I have gone through some other solutions given on here but they all use matplotlib libray while mine doesn't require matplotlib and I haven't mentioned it in requirements.txt file either but it gets installed on when deploying on heroku. I know the heroku does not support _tkinter. So what else can I do for it to run properly?

python version:3.8.8

I can provide more details if required.

  • you you should operate from virtualenv and install all your dependencies inside it, and when you freeze requirements.txt, your venv should be activated and in project directory. Else, freeze will put all modules installed in your pc. Else, it is impossible to serve tkinter, Heroku is a webserver not software server! – HB21 Oct 29 '21 at 10:16
  • I am wokring from virtualenv. Matplotlib and some libraries aren't mentioned in requirements.txt but they get installed on heroku eitherway for some reason. Regarding tkinter I am not using it in my program atall. I dont know why its popping up. – Chinmay Datar Oct 29 '21 at 10:46
  • Probably you freezed requirements.txt outside the project directory or while virtualvenv is not activated. Then after freezing requirements.txt, venv should be deactivated. And while you still in project directory, `git add -A`, `git commit -m "my comment"` and `git push heroku master`, of course if there is an existed app, before pushing, you should do `heroku git:remote -a myapp` – HB21 Oct 29 '21 at 10:56
  • I double checked. I have done all of what you said. – Chinmay Datar Oct 29 '21 at 11:24
  • The problem got solved by just adding ```import matplotlib matplotlib.use('Agg') # Must be done before importing pyplot import matplotlib.pyplot as plt``` to the models file even if you are not using it. – Chinmay Datar Oct 29 '21 at 11:25
  • if your project doesn't need matplotlib, then why it should be installed? – HB21 Oct 29 '21 at 11:28
  • It does not need to be but it was getting installed even without being mentioned in the requirements.txt (I have checked several times now). Eitherway the above thing solved the problem for me. – Chinmay Datar Oct 29 '21 at 11:34
  • Had the same error, try with this solution https://stackoverflow.com/a/69335260/17815679 – shyakadev Feb 28 '22 at 16:38

2 Answers2

1

I had the same error deploying my django app to Heroku. I found that I was importing CASCADE from tkinter in my models.py file. I changed

from tkinder import CASCADE

To

from django.db.models.deletion import CASCADE

and this fixed my issue.

Suraj Rao
  • 28,850
  • 10
  • 94
  • 99
0

I was trying to deploy an application to Heroku and was getting this error.

This error might be because of the import of tkinter somewhere in our code. please check properly and remove it.

enter image description here

  • 1
    If you have a new question, please ask it by clicking the [Ask Question](https://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. - [From Review](/review/late-answers/30883559) – BrokenBenchmark Jan 29 '22 at 06:35
  • As far as I can tell, this person is not trying to ask their own question; they are saying that they had this problem in the past and giving the solution to it. It is just worded poorly – Lecdi May 09 '22 at 17:17