这是我第一次尝试部署到Heroku,但我一直收到应用程序错误。我有CLI,它会给我日志,但我在理解它时遇到了困难。如有任何帮助,我们将不胜感激。这是日志。。。
$ heroku logs --tail -a weather-project-test
2021-11-22T21:50:27.798942+00:00 app[web.1]: raise ImportError("Unable to find tkinter package.")
2021-11-22T21:50:27.798942+00:00 app[web.1]: ImportError: Unable to find tkinter package.
2021-11-22T21:50:27.798942+00:00 app[web.1]:
2021-11-22T21:50:27.798942+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2021-11-22T21:50:27.798942+00:00 app[web.1]:
2021-11-22T21:50:27.798943+00:00 app[web.1]: Traceback (most recent call last):
2021-11-22T21:50:27.798943+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2021-11-22T21:50:27.798943+00:00 app[web.1]: worker.init_process()
2021-11-22T21:50:27.798944+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 134, in init_process
2021-11-22T21:50:27.798944+00:00 app[web.1]: self.load_wsgi()
2021-11-22T21:50:27.798944+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-11-22T21:50:27.798944+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-11-22T21:50:27.798944+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-11-22T21:50:27.798945+00:00 app[web.1]: self.callable = self.load()
2021-11-22T21:50:27.798945+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-11-22T21:50:27.798946+00:00 app[web.1]: return self.load_wsgiapp()
2021-11-22T21:50:27.798946+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-11-22T21:50:27.798946+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-11-22T21:50:27.798946+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/util.py", line 359, in import_app
2021-11-22T21:50:27.798947+00:00 app[web.1]: mod = importlib.import_module(module)
2021-11-22T21:50:27.798947+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/importlib/__init__.py", line 127, in import_module
2021-11-22T21:50:27.798947+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-11-22T21:50:27.798948+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
2021-11-22T21:50:27.798948+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
2021-11-22T21:50:27.798948+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
2021-11-22T21:50:27.798948+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
2021-11-22T21:50:27.798949+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 850, in exec_module
2021-11-22T21:50:27.798949+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
2021-11-22T21:50:27.798949+00:00 app[web.1]: File "/app/app.py", line 6, in <module>
2021-11-22T21:50:27.798949+00:00 app[web.1]: import easygui
2021-11-22T21:50:27.798950+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/easygui/__init__.py", line 34, in <module>
2021-11-22T21:50:27.798950+00:00 app[web.1]: from .boxes.button_box import buttonbox
2021-11-22T21:50:27.798950+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/easygui/boxes/button_box.py", line 18, in <module>
2021-11-22T21:50:27.798950+00:00 app[web.1]: import global_state
2021-11-22T21:50:27.798951+00:00 app[web.1]: ModuleNotFoundError: No module named 'global_state'
2021-11-22T21:50:27.799086+00:00 app[web.1]: [2021-11-22 21:50:27 +0000] [10] [INFO] Worker exiting (pid: 10)
2021-11-22T21:50:27.838293+00:00 app[web.1]: [2021-11-22 21:50:27 +0000] [9] [ERROR] Exception in worker process
2021-11-22T21:50:27.838294+00:00 app[web.1]: Traceback (most recent call last):
2021-11-22T21:50:27.838294+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/easygui/boxes/utils.py", line 29, in <module>
2021-11-22T21:50:27.838295+00:00 app[web.1]: import tkinter as tk # python3
2021-11-22T21:50:27.838295+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/tkinter/__init__.py", line 37, in <module>
2021-11-22T21:50:27.838296+00:00 app[web.1]: import _tkinter # If this fails your Python may not be configured for Tk
2021-11-22T21:50:27.838296+00:00 app[web.1]: ModuleNotFoundError: No module named '_tkinter'
2021-11-22T21:50:27.838296+00:00 app[web.1]:
2021-11-22T21:50:27.838299+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2021-11-22T21:50:27.838299+00:00 app[web.1]:
2021-11-22T21:50:27.838300+00:00 app[web.1]: Traceback (most recent call last):
2021-11-22T21:50:27.838300+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/easygui/boxes/utils.py", line 36, in <module>
2021-11-22T21:50:27.838300+00:00 app[web.1]: import Tkinter as tk # python2
2021-11-22T21:50:27.838300+00:00 app[web.1]: ModuleNotFoundError: No module named 'Tkinter'
2021-11-22T21:50:27.838300+00:00 app[web.1]:
2021-11-22T21:50:27.838301+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2021-11-22T21:50:27.838301+00:00 app[web.1]:
2021-11-22T21:50:27.838301+00:00 app[web.1]: Traceback (most recent call last):
2021-11-22T21:50:27.838301+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/easygui/boxes/button_box.py", line 15, in <module>
2021-11-22T21:50:27.838302+00:00 app[web.1]: from . import utils as ut
2021-11-22T21:50:27.838302+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/easygui/boxes/utils.py", line 43, in <module>
2021-11-22T21:50:27.838302+00:00 app[web.1]: raise ImportError("Unable to find tkinter package.")
2021-11-22T21:50:27.838302+00:00 app[web.1]: ImportError: Unable to find tkinter package.
2021-11-22T21:50:27.838303+00:00 app[web.1]:
2021-11-22T21:50:27.838303+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2021-11-22T21:50:27.838303+00:00 app[web.1]:
2021-11-22T21:50:27.838303+00:00 app[web.1]: Traceback (most recent call last):
2021-11-22T21:50:27.838303+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2021-11-22T21:50:27.838304+00:00 app[web.1]: worker.init_process()
2021-11-22T21:50:27.838310+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 134, in init_process
2021-11-22T21:50:27.838311+00:00 app[web.1]: self.load_wsgi()
2021-11-22T21:50:27.838311+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-11-22T21:50:27.838311+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-11-22T21:50:27.838311+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-11-22T21:50:27.838311+00:00 app[web.1]: self.callable = self.load()
2021-11-22T21:50:27.838312+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-11-22T21:50:27.838312+00:00 app[web.1]: return self.load_wsgiapp()
2021-11-22T21:50:27.838312+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-11-22T21:50:27.838312+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-11-22T21:50:27.838312+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/util.py", line 359, in import_app
2021-11-22T21:50:27.838313+00:00 app[web.1]: mod = importlib.import_module(module)
2021-11-22T21:50:27.838313+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/importlib/__init__.py", line 127, in import_module
2021-11-22T21:50:27.838313+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-11-22T21:50:27.838313+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
2021-11-22T21:50:27.838314+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
2021-11-22T21:50:27.838314+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
2021-11-22T21:50:27.838314+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
2021-11-22T21:50:27.838315+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 850, in exec_module
2021-11-22T21:50:27.838315+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
2021-11-22T21:50:27.838315+00:00 app[web.1]: File "/app/app.py", line 6, in <module>
2021-11-22T21:50:27.838315+00:00 app[web.1]: import easygui
2021-11-22T21:50:27.838315+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/easygui/__init__.py", line 34, in <module>
2021-11-22T21:50:27.838316+00:00 app[web.1]: from .boxes.button_box import buttonbox
2021-11-22T21:50:27.838316+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/easygui/boxes/button_box.py", line 18, in <module>
2021-11-22T21:50:27.838316+00:00 app[web.1]: import global_state
2021-11-22T21:50:27.838316+00:00 app[web.1]: ModuleNotFoundError: No module named 'global_state'
2021-11-22T21:50:27.838439+00:00 app[web.1]: [2021-11-22 21:50:27 +0000] [9] [INFO] Worker exiting (pid: 9)
2021-11-22T21:50:27.900802+00:00 app[web.1]: [2021-11-22 21:50:27 +0000] [4] [WARNING] Worker with pid 9 was terminated due to signal 15
2021-11-22T21:50:27.996720+00:00 app[web.1]: [2021-11-22 21:50:27 +0000] [4] [INFO] Shutting down: Master
2021-11-22T21:50:27.996760+00:00 app[web.1]: [2021-11-22 21:50:27 +0000] [4] [INFO] Reason: Worker failed to boot.
2021-11-22T21:50:28.128570+00:00 heroku[web.1]: Process exited with status 3
2021-11-22T21:50:29.097421+00:00 heroku[web.1]: State changed from up to crashed
2021-11-22T21:50:32.000000+00:00 app[api]: Build succeeded
2021-11-22T21:50:33.543848+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=weather-project-test.herokuapp.com request_id=cf370789-3a16-41f1-b36d-5fee0fcbab43 fwd="71.66.229.159" dyno=web.1 connect=5000ms service= status=503 bytes= protocol=https
我的requirements.txt文件如下:
easygui==0.98.2
Flask==2.0.1
Flask_PyMongo==2.3.0
numpy==1.21.2
pandas==1.3.2
pymongo==3.12.0
requests==2.26.0
Werkzeug==2.0.1
gunicorn>=20.1.0
Procfile如下:
web: gunicorn app:app
最后是我的app.py 代码
from flask import Flask, render_template
from logging import debug
from flask_pymongo import PyMongo
from werkzeug.utils import append_slash_redirect, redirect
from script import api_call
import easygui
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route("/script")
def script():
api_call()
easygui.msgbox("Database Updated Successfully!", "Success")
return redirect("/")
@app.route("/heatmap")
def heatmap():
return render_template('heatmap.html')
if __name__ == '__main__':
app.run()
这是easygui和尝试导入tkinter的问题。之后,渲染模板无法正常工作。我很乐意重组文件,一切都很好。谢谢