在Heroku上访问我的网站
我在Heroku服务器上部署了一个Flask应用程序,但它不起作用
我在浏览器中看到这个
I've deployed a Flask application on Heroku server but it isn't working I see this in the browser
应用程序错误应用程序发生错误,您的页面
无法投放。如果您是应用程序所有者,请查看您的日志
了解详情。
Application error An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.
导致此错误的原因是什么?
What causes this error?
当我运行 heroku日志
时,我得到了以下内容这些东西是什么,我该如何解决它?
I got the following when I run heroku logs
What are these things and how can I fix it?
2018-04-25T18:51:16.513351+00:00 app[web.1]: _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
2018-04-25T18:51:16.513353+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-ile "/app/.heroku/python/lib/python3.6/site-packages/matplotlib/backends/backend_tkagg.py", line 4, in <module>
2018-04-25T18:51:16.596215+00:00 app[web.1]: from . import tkagg # Paint image to Tk photo blitter extension.
2018-04-25T18:51:16.596217+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/matplotlib/backends/tkagg.py", line 5, in <module>
2018-04-25T18:51:16.596218+00:00 app[web.1]: from six.moves import tkinter as Tk
2018-04-25T18:51:16.596220+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/six.py", line 92, in __get__
2018-04-25T18:51:16.596222+00:00 app[web.1]: result = self._resolve()
2018-04-25T18:51:16.596223+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/six.py", line 115, in _resolve
2018-04-25T18:51:16.596225+00:00 app[web.1]: return _import_module(self.mod)
2018-04-25T18:51:16.596227+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/six.py", line 82, in _import_module
2018-04-25T18:51:16.596229+00:00 app[web.1]: __import__(name)
2018-04-25T18:51:16.596230+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/tkinter/__init__.py", line 36, in <module>
2018-04-25T18:51:16.596232+00:00 app[web.1]: import _tkinter # If this fails your Python may not be configured for Tk
2018-04-25T18:51:16.596720+00:00 app[web.1]: [2018-04-25 18:51:16 +0000] [9] [INFO] Worker exiting (pid: 9)
2018-04-25T18:51:16.596241+00:00 app[web.1]: ModuleNotFoundError: No module named '_tkinter'
2018-04-25T18:51:16.739539+00:00 app[web.1]: [2018-04-25 18:51:16 +0000] [4] [INFO] Shutting down: Master
2018-04-25T18:51:16.741786+00:00 app[web.1]: [2018-04-25 18:51:16 +0000] [4] [INFO] Reason: Worker failed to boot.
2018-04-25T18:51:16.862528+00:00 heroku[web.1]: State changed from up to crashed
2018-04-25T18:51:16.850843+00:00 heroku[web.1]: Process exited with status 3
(venv) MacBook-Pro-alkhas-b-Amjad:flaskhpbio joodi$
这是否意味着缺少某些东西?
Does this mean there are things missing?
您的回溯表明您的应用程序正在尝试导入 Tkinter :
Your traceback shows that your application is trying to import Tkinter:
ModuleNotFoundError:没有名为'_tkinter'的模块
ModuleNotFoundError: No module named '_tkinter'
听起来像 matplotlib
是试图进行导入的库。
It sounds like matplotlib
is the library that's trying to do the import.
Tkinter在Heroku上不可用。好消息是 matplotlib
支持多个后端,其中一些在无头服务器上工作。尝试修改您的代码以使用不同的后端,例如 Agg
:
Tkinter isn't available on Heroku. The good news is that matplotlib
supports multiple backends, some of which work on headless servers. Try modifying your code to use a different backend, like Agg
:
import matplotlib
matplotlib.use('Agg') # Must be done before importing pyplot
import matplotlib.pyplot as plt
如果您使用
use()
函数,则必须在导入matplotlib.pyplot
。在pyplot
之后调用use()
将不起作用。如果用户想使用不同的后端,使用use()
将需要更改代码。因此,除非绝对必要,否则应该避免显式调用use()
。
If you use the
use()
function, this must be done before importingmatplotlib.pyplot
. Callinguse()
afterpyplot
has been imported will have no effect. Usinguse()
will require changes in your code if users want to use a different backend. Therefore, you should avoid explicitly callinguse()
unless absolutely necessary.
您必须提交此更改并将其推送到Heroku。
You'll have to commit this change and push it to Heroku.