简体   繁体   English

ModuleNotFoundError:没有名为“_tkinter”的模块 Heroku

[英]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.我正在尝试使用 Heroku 部署一个 webapp,它已被部署,但当我尝试打开它时它会出现内部服务器错误。 The complete log as from heroku logs -t is as follows: heroku logs -t的完整日志如下:

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.我已经完成了此处给出的其他一些解决方案,但它们都使用 matplotlib 库,而我的不需要 matplotlib 并且我也没有在requirements.txt文件中提到它,但是它在部署时安装在 Z3115FB34DFCB568AA049707 I know the heroku does not support _tkinter .我知道 heroku 不支持_tkinter So what else can I do for it to run properly?那么我还能做些什么让它正常运行呢?

python version:3.8.8 python 版本:3.8.8

I can provide more details if required.如果需要,我可以提供更多详细信息。

I had the same error deploying my django app to Heroku.将我的 django 应用程序部署到 Heroku 时,我遇到了同样的错误。 I found that I was importing CASCADE from tkinter in my models.py file.我发现我在我的 models.py 文件中从 tkinter 导入 CASCADE。 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.有时它并不总是在 models.py 文件中。 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.如果您遇到这种情况,请继续阅读错误消息,您最终会找到导入 tkinter 的文件。 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.所以我只需要删除我的 blog/views.py 文件中的第一行。 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.根据这个链接,PySimpleGUI 是一个包装 tkinter 的 python 库。 And that alone gives us the solution.仅此一项就为我们提供了解决方案。 so delete that import from your apis/model.py.所以从你的 apis/model.py 中删除那个导入。

*make sure you commit that change to your git repo and push again to heroku. *确保您将更改提交到您的 git repo 并再次推送到 heroku。

I was trying to deploy an application to Heroku and was getting this error.我试图将应用程序部署到 Heroku 并收到此错误。

This error might be because of the import of tkinter somewhere in our code.这个错误可能是因为在我们的代码中某处导入了 tkinter。 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.几天前我遇到了同样的问题,我发现title是由 vs code 自动导入的。 Carefully check all the imports on your script.仔细检查脚本上的所有导入。 Something was likely auto-imported.某些东西可能是自动导入的。

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

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