简体   繁体   中英

ModuleNotFoundError: No module named '_tkinter' Heroku

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.

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.

Sometimes it is not always in the models.py file. If that happens to be your case, keep on reading the error message, you will eventually find the file in which tkinter in being imported. I did so and it was at the bottom of the error where I found this:

  File "/app/blog/views.py", line 1, in <module>
from turtle import home

So I just had to delete the first line in my blog/views.py file. And It worked!

So in your case, I think the problem is displayed at.

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

According to this link , PySimpleGUI is a python library that wraps tkinter. And that alone gives us the solution. so delete that import from your apis/model.py.

*make sure you commit that change to your git repo and push again to heroku.

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.

在此处输入图像描述

Not sure if you still need an answer for this, but I ran into the same problem. I fixed it by removing all unused imports on my project. After doing this and redeploying, I was able to resolve this issue, hope this helps

I had the same issue some days back and I found out that title was auto-imported by vs code. Carefully check all the imports on your script. Something was likely auto-imported.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM