ModuleNotFoundError: No module named '_tkinter'
Verfasst: Donnerstag 16. August 2018, 23:35
Hallo ich versuche diesen code hier auf meinen Heroku webserver zuladen Dabei kommt immer diese Fehlermeldung im Log das ganze hat offensichtlich was mit "matplotlib.pyplot" zu tun da wenn ich diesen import auskommentiere wir der Fehler nicht mehr angezeigt. Weiß irgendwer wie ich das Problem lösen kann?
Fehler:
Code: Alles auswählen
from flask import Flask, render_template, url_for, request
import datetime #Uhrzeit
import pytz #Zeitzone
import csv #Csv Datei schreiben
import matplotlib.pyplot as plt #Csv Daten plotten
app = Flask(__name__)
with open('data/data.csv') as lines:
reader = csv.reader(lines, delimiter=',')
tabelle = [
row[:1] + [float(c) for c in row[1:]]
for row in reader
]
@app.route('/')
@app.route('/index')
def index():
return render_template('index.html')
@app.route('/test')
def test():
return render_template('test.html')
@app.route('/getdata', methods=['GET', 'POST'])
def getdata():
if request.method == 'POST':
file = open('test.txt', "a")
data = request.data
my_date = datetime.datetime.now(pytz.timezone('Europe/Berlin'))
fmt = "%Y-%m-%d %H:%M:%S"
for i in data:
file.write(my_date.strftime(fmt) + "; ")
file.write(str(data) + '\n')
file.close()
return data
return render_template('getdata.html')
@app.route('/data/luftfeuchtigkeit')
def luftfeuchtigkeit():
time = [zeile[0] for zeile in tabelle]
luftfeuchtedrin = [zeile[1] for zeile in tabelle]
luftfeuchteausen = [zeile[3] for zeile in tabelle]
fig, ax = plt.subplots()
ax.plot(time, luftfeuchtedrin, label="Luftfeuchtigkeit drin")
ax.plot(time, luftfeuchteausen, label="Luftfeuchtigkeit ausen")
ax.grid(True)
ax.legend()
ax.set_title('Luftfeuchtigkeit')
ax.set_ylabel('Luftfeuchtigkeit in %')
ax.set_xlabel('Uhrzeit')
plt.savefig('data/pictures/luftfeuchtigkeit.png', dpi=None, transparent=True)
@app.route('/data/temperatur')
def temperatur():
time = [zeile[0] for zeile in tabelle]
tempraturdrin = [zeile[2] for zeile in tabelle]
temperaturausen = [zeile[4] for zeile in tabelle]
fig, ax = plt.subplots()
ax.plot(time, tempraturdrin, label="Temperatur drin")
ax.plot(time, temperaturausen, label="Temperatur ausen")
ax.grid(True)
ax.legend()
ax.set_title('Temperatur')
ax.set_ylabel('Temperatur in Celsius')
ax.set_xlabel('Uhrzeit')
plt.savefig('data/pictures/temperatur.png', dpi=None, transparent=True)
@app.route('/data/erdfeuchtigkeit')
def erdfeuchtigkeit():
time = [zeile[0] for zeile in tabelle]
erdfeuchte = [zeile[5] for zeile in tabelle]
fig, ax = plt.subplots()
ax.plot(time, erdfeuchte, label="Erdfeuchtigkeit")
ax.grid(True)
ax.legend()
ax.set_title('Erdfeuchtigkeit')
ax.set_ylabel('Erdfeuchtigkeit')
ax.set_xlabel('Uhrzeit')
plt.savefig('data/pictures/erdfeuchtigkeit.png', dpi=None, transparent=True)
@app.route('/data/lux')
def lux():
time = [zeile[0] for zeile in tabelle]
lux = [zeile[6] for zeile in tabelle]
fig, ax = plt.subplots()
ax.plot(time, lux, label="Lichtitensität(lux)")
ax.grid(True)
fig.legend()
ax.set_title('Lichtitensität(lux)')
ax.set_ylabel('Lux')
ax.set_xlabel('Uhrzeit')
plt.savefig('data/pictures/lux.png', dpi=None, transparent=True)
return render_template('file.html')
if __name__ == '__main__': app.run(debug=True)
Code: Alles auswählen
2018-08-16T22:33:34.442512+00:00 app[web.1]: Traceback (most recent call last):
2018-08-16T22:33:34.442514+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2018-08-16T22:33:34.442515+00:00 app[web.1]: worker.init_process()
2018-08-16T22:33:34.442517+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
2018-08-16T22:33:34.442518+00:00 app[web.1]: self.load_wsgi()
2018-08-16T22:33:34.442519+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2018-08-16T22:33:34.442524+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2018-08-16T22:33:34.442525+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2018-08-16T22:33:34.442527+00:00 app[web.1]: self.callable = self.load()
2018-08-16T22:33:34.442528+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2018-08-16T22:33:34.442529+00:00 app[web.1]: return self.load_wsgiapp()
2018-08-16T22:33:34.442530+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2018-08-16T22:33:34.442532+00:00 app[web.1]: return util.import_app(self.app_uri)
2018-08-16T22:33:34.442533+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
2018-08-16T22:33:34.442534+00:00 app[web.1]: __import__(module)
2018-08-16T22:33:34.442535+00:00 app[web.1]: File "/app/app.py", line 5, in <module>
2018-08-16T22:33:34.442537+00:00 app[web.1]: import matplotlib.pyplot as plt #Csv Daten plotten
2018-08-16T22:33:34.442538+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/matplotlib/pyplot.py", line 115, in <module>
2018-08-16T22:33:34.442539+00:00 app[web.1]: _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
2018-08-16T22:33:34.442541+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
2018-08-16T22:33:34.442542+00:00 app[web.1]: [backend_name], 0)
2018-08-16T22:33:34.442543+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/matplotlib/backends/backend_tkagg.py", line 4, in <module>
2018-08-16T22:33:34.442544+00:00 app[web.1]: from . import tkagg # Paint image to Tk photo blitter extension.
2018-08-16T22:33:34.442546+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/matplotlib/backends/tkagg.py", line 5, in <module>
2018-08-16T22:33:34.442547+00:00 app[web.1]: from six.moves import tkinter as Tk
2018-08-16T22:33:34.442548+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/six.py", line 92, in __get__
2018-08-16T22:33:34.442550+00:00 app[web.1]: result = self._resolve()
2018-08-16T22:33:34.442551+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/six.py", line 115, in _resolve
2018-08-16T22:33:34.442552+00:00 app[web.1]: return _import_module(self.mod)
2018-08-16T22:33:34.442554+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/six.py", line 82, in _import_module
2018-08-16T22:33:34.442555+00:00 app[web.1]: __import__(name)
2018-08-16T22:33:34.442556+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/tkinter/__init__.py", line 36, in <module>
2018-08-16T22:33:34.442557+00:00 app[web.1]: import _tkinter # If this fails your Python may not be configured for Tk
2018-08-16T22:33:34.442558+00:00 app[web.1]: ModuleNotFoundError: No module named '_tkinter'