模块未找到错误:没有名为"_tkinter"的模块Heroku

ajsxfq5m  于 2023-02-16  发布在  其他
关注(0)|答案(4)|浏览(126)

我正在尝试使用Heroku部署一个Web应用程序,它得到部署,但它给出内部服务器错误,当我尝试打开它。从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

我已经看过这里给出的一些其他解决方案,但它们都使用matplotlib库,而我的不需要matplotlib,我也没有在requirements.txt文件中提到它,但它会在部署到heroku时安装。我知道heroku不支持_tkinter。那么我还能做些什么来让它正常运行呢?
Python版本:3.8.8
如有需要,我可以提供更多细节。

zzlelutf

zzlelutf1#

我在部署我的django应用到Heroku时也遇到了同样的错误。我发现我正在从tkinter导入CASCADE到我的models.py文件中。我更改了

from tkinder import CASCADE

from django.db.models.deletion import CASCADE

这解决了我的问题。
有时它并不总是在models.py文件中。如果你遇到这种情况,继续阅读错误消息,你最终会找到tkinter被导入的文件。我这样做了,它是在错误的底部,我发现了这个:

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

所以我只需要删除我博客/ www.example.com文件中的第一行views.py。而且它起作用了!
因此,在您的情况下,我认为问题显示在。

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

根据this link,PySimpleGUI是一个 Package tkinter的python库,仅此一项就给了我们解决方案。因此,请从apis/model.py中删除该导入。

  • 确保将更改提交到git repo,然后再次推送到heroku。
wgx48brx

wgx48brx2#

几天前我遇到过同样的问题,我发现title是由vs代码自动导入的。仔细检查你脚本中的所有导入。有些东西可能是自动导入的。

jutyujz0

jutyujz03#

我试图将应用程序部署到Heroku,但遇到此错误。
这个错误可能是因为在我们代码的某个地方导入了tkinter。请正确检查并删除它。

vnjpjtjt

vnjpjtjt4#

我遇到了同样的问题。我通过删除项目上所有未使用的导入来修复它。在这样做并重新部署之后,我能够解决这个问题。

相关问题