Hello, recently fresh release of Raspbian OS with QT4 and pyqtgraph
librarry was installed and project which run before, don't run anymore.
Here is error text which I got running my project and graph script is
attached.
With best regards, Vlado
Error text:
*Traceback (most recent call last): File "/home/pi/Desktop/Sušilec
sadja/Project/main.py", line 29, in <module> from graph_2 import * File
"/home/pi/Desktop/Sušilec sadja/Project/graph_2.py", line 3, in <module>
import pyqtgraph as pg File
"/usr/local/lib/python3.7/dist-packages/pyqtgraph/__init__.py", line 13, in
<module> from .Qt import QtCore, QtGui, mkQApp File
"/usr/local/lib/python3.7/dist-packages/pyqtgraph/Qt/__init__.py", line 49,
in <module> raise Exception("PyQtGraph requires one of PyQt5, PyQt6,
PySide2 or PySide6; none of these packages could be imported.")Exception:
PyQtGraph requires one of PyQt5, PyQt6, PySide2 or PySide6; none of these
packages could be imported.*
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/7de2bb12-21d9-4abc-b2c2-ffcf6bc09f3dn%40googlegroups.com.
import time
import sys
import pyqtgraph as pg
from PyQt4 import QtGui
import numpy
from pyqtgraph import AxisItem
from datetime import datetime, timedelta
from time import mktime
import datetime as dt
from Buffer_script import *
pg.setConfigOptions(antialias=True)
pg.setConfigOption('background', '#c7c7c7')
pg.setConfigOption('foreground', '#000000')
now_time = 0
OUT_Buffer_ogrevanje_zgoraj = [10, 20, 30, 40, 50, 60, 70, 80, 90, 80, 70, 60,
50, 40, 30, 20, 10, 20, 30, 40, 50, 60, 70, 80, 90, 80, 90, 80, 70, 80,
100] # 31spominskih
OUT_Buffer_ogrevanje_spodaj = [10, 20, 30, 40, 50, 60, 70, 80, 90, 80, 70, 60,
50, 40, 30, 20, 10, 20, 30, 40, 50, 60, 70, 80, 90, 80, 90, 80, 70, 80,
100] # 31 spominskih mest
OUT_Buffer_ogrevanje_bojler = [10, 20, 30, 40, 50, 60, 70, 80, 90, 80, 70, 60,
50, 40, 30, 20, 10, 20, 30, 40, 50, 60, 70, 80, 90, 80, 90, 80, 70, 80,
100] # 31 spominskih mest
OUT_Buffer_ogrevanje_drva = [10, 20, 30, 40, 50, 60, 70, 80, 90, 80, 70, 60,
50, 40, 30, 20, 10, 20, 30, 40, 50, 60, 70, 80, 90, 80, 90, 80, 70, 80,
100] # 31 spominskih mest
timestamps_31 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
OUT_Buffer_kWh_3h = [0, 10, 20, 30, 30, 30, 30, 40, 40, 40, 50, 50, 50, 50,
50, 50, 60, 60, 0, 10, 10, 10, 10, 10, 20, 20, 20, 20, 30, 30, 30, 30, 30,
30,
40, 40, 40, 40, 50, 50, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60,
60,
70, 70, 70, 70, 70, 70, 70, 80, 80, 80, 0, 10, 10, 10, 20, 30, 30, 30, 30,
30,
40, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
10, 10, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 20,
0, 0, 0, 0, 0, 0, 0] # 181 spominskih mest
#===============================================================================
#-------------------------------------------------------------------------------
OUT_Buffer_Temperatura = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # 46 mest
#-------------------------------------------------------------------------------
OUT_Buffer_Temp_SetPoint = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # 46 mest
#-------------------------------------------------------------------------------
OUT_Buffer_Regulator = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # 46 mest
#-------------------------------------------------------------------------------
OUT_Buffer_Output = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # 46 mest
#------------------------------------------------------------------------------
class DateAxisItem(AxisItem):
"""
A tool that provides a date-time aware axis. It is implemented as an
AxisItem that interpretes positions as unix timestamps (i.e. seconds
since 1970).
The labels and the tick positions are dynamically adjusted depending
on the range.
It provides a :meth:`attachToPlotItem` method to add it to a given
PlotItem
"""
# Max width in pixels reserved for each label in axis
_pxLabelWidth = 80
#_pxLabelWidth = 200
def __init__(self, *args, **kwargs):
AxisItem.__init__(self, *args, **kwargs)
self._oldAxis = None
def tickValues(self, minVal, maxVal, size):
"""
Reimplemented from PlotItem to adjust to the range and to force
the ticks at "round" positions in the context of time units instead of
rounding in a decimal base
"""
maxMajSteps = int(size/self._pxLabelWidth)
#print(maxMajSteps)
dt1 = datetime.fromtimestamp(minVal)
dt2 = datetime.fromtimestamp(maxVal)
#print(dt1, dt2)
dx = maxVal - minVal
#print("dx", dx)
majticks = []
if dx > 63072001: # 3600s*24*(365+366) = 2 years (count leap year)
d = timedelta(days=366)
for y in range(dt1.year + 1, dt2.year):
dt = datetime(year=y, month=1, day=1)
majticks.append(mktime(dt.timetuple()))
elif dx > 5270400: # 3600s*24*61 = 61 days
d = timedelta(days=31)
dt = dt1.replace(day=1, hour=0, minute=0,
second=0, microsecond=0) + d
while dt < dt2:
# make sure that we are on day 1 (even if always sum 31 days)
dt = dt.replace(day=1)
majticks.append(mktime(dt.timetuple()))
dt += d
elif dx > 172800: # 3600s24*2 = 2 days
d = timedelta(days=1)
dt = dt1.replace(hour=0, minute=0, second=0, microsecond=0) + d
while dt < dt2:
majticks.append(mktime(dt.timetuple()))
dt += d
#print("2 days")
elif dx > 7200: # 3600s*2 = 2hours
d = timedelta(hours=1)
dt = dt1.replace(minute=0, second=0, microsecond=0) + d
while dt < dt2:
majticks.append(mktime(dt.timetuple()))
dt += d
#print("2 hours", dt)
elif dx > 1200: # 60s*20 = 20 minutes
d = timedelta(minutes=10)
dt = dt1.replace(minute=(dt1.minute // 10) * 10,
second=0, microsecond=0) + d
while dt < dt2:
majticks.append(mktime(dt.timetuple()))
dt += d
#print("20 min")
elif dx > 120: # 60s*2 = 2 minutes
d = timedelta(minutes=1)
dt = dt1.replace(second=0, microsecond=0) + d
while dt < dt2:
majticks.append(mktime(dt.timetuple()))
dt += d
elif dx > 20: # 20s
d = timedelta(seconds=10)
dt = dt1.replace(second=(dt1.second // 10) * 10, microsecond=0) + d
while dt < dt2:
majticks.append(mktime(dt.timetuple()))
dt += d
#print("20 sec")
elif dx > 2: # 2s
d = timedelta(seconds=1)
majticks = range(int(minVal), int(maxVal))
else: # <2s , use standard implementation from parent
return AxisItem.tickValues(self, minVal, maxVal, size)
L = len(majticks)
if L > maxMajSteps:
majticks = majticks[::int(numpy.ceil(float(L) / maxMajSteps))]
return [(d.total_seconds(), majticks)]
def tickStrings(self, values, scale, spacing):
"""Reimplemented from PlotItem to adjust to the range"""
ret = []
if not values:
return []
if spacing >= 31622400: # 366 days
fmt = "%Y"
elif spacing >= 2678400: # 31 days
fmt = "%Y %b"
#print("Month")
elif spacing >= 86400: # = 1 day
fmt = "%b/%d"
#print("Day")
elif spacing >= 3600: # 1 h
#fmt = "%b/%d-%Hh"
fmt = "%Hh"
#print("Hour")
elif spacing >= 60: # 1 m
fmt = "%H:%M"
#print("Minutte")
elif spacing >= 1: # 1s
fmt = "%H:%M:%S"
else:
# less than 2s (show microseconds)
# fmt = '%S.%f"'
fmt = '[+%fms]' # explicitly relative to last second
for x in values:
try:
t = datetime.fromtimestamp(x)
ret.append(t.strftime(fmt))
except ValueError: # Windows can't handle dates before 1970
ret.append('')
#print("ret", ret)
return ret
def attachToPlotItem(self, plotItem):
"""Add this axis to the given PlotItem
:param plotItem: (PlotItem)
"""
self.setParentItem(plotItem)
viewBox = plotItem.getViewBox()
self.linkToView(viewBox)
self._oldAxis = plotItem.axes[self.orientation]['item']
self._oldAxis.hide()
plotItem.axes[self.orientation]['item'] = self
pos = plotItem.axes[self.orientation]['pos']
plotItem.layout.addItem(self, *pos)
self.setZValue(-1000)
#------------------------------------------------------------------------------
def graph_temperatura():
global OUT_Buffer_Temperatura, OUT_Buffer_Temp_SetPoint
timelist = []
x = []
n = 46
i = 0
H = pg.plot()
#H.resize(1200, 500)
while i < n:
x.append(i)
i += 1
currentTime = dt.datetime.now().strftime("%M")
timelist.append(currentTime)
timelist = timelist[-n:]
for i in range(0, n):
timelist[i] = int(timelist[i])
i = n
j = 0
while i > 0:
timelist[i - 1] = timelist[i - 1] - j
if timelist[i - 1] < 0:
timelist[i - 1] = timelist[i - 1] + 60
j += 1
i -= 1
for i in range(0, n):
timelist[i] = str(timelist[i])
H.plot(x, OUT_Buffer_Temperatura,pen=pg.mkPen(
color='#ff0000', width=5))
H.plot(x, OUT_Buffer_Temp_SetPoint,pen=pg.mkPen(
color='#00ff70', width=5))
H.setTitle('Temperatura (Rd), Setpoint (Ze)')
H.showGrid(True, True)
H.setLabel('left', 'Temperatura', units='deg C', **{'font-size': '20pt'})
H.setLabel('bottom', 'Cas', units='min', **{'font-size': '20pt'})
ticks = list(enumerate(timelist))
ticks = ticks[::5]
ax = H.getAxis("bottom")
ax.setTicks([ticks])
#------------------------------------------------------------------------------
def graph_regulator():
global OUT_Buffer_Regulator, OUT_Buffer_Output
timelist = []
x = []
n = 46
i = 0
H = pg.plot()
#H.resize(1200, 500)
while i < n:
x.append(i)
i += 1
currentTime = dt.datetime.now().strftime("%M")
timelist.append(currentTime)
timelist = timelist[-n:]
for i in range(0, n):
timelist[i] = int(timelist[i])
i = n
j = 0
while i > 0:
timelist[i - 1] = timelist[i - 1] - j
if timelist[i - 1] < 0:
timelist[i - 1] = timelist[i - 1] + 60
j += 1
i -= 1
for i in range(0, n):
timelist[i] = str(timelist[i])
H.plot(x, OUT_Buffer_Regulator,pen=pg.mkPen(
color='#0000ff', width=5))
H.plot(x, OUT_Buffer_Output,pen=pg.mkPen(
color='y', width=5))
H.setTitle('Regulator (Mo), Output (Ru)')
H.showGrid(True, True)
H.setLabel('left', 'Output', units='%', **{'font-size': '20pt'})
H.setLabel('bottom', 'Cas', units='min', **{'font-size': '20pt'})
ticks = list(enumerate(timelist))
ticks = ticks[::5]
ax = H.getAxis("bottom")
ax.setTicks([ticks])
#-------------------------------------------------------------------------------
def graph_all():
global OUT_Buffer_Temperatura, OUT_Buffer_Temp_SetPoint
global OUT_Buffer_Regulator, OUT_Buffer_Output
timelist = []
x = []
n = 46
i = 0
H = pg.plot()
#H.resize(1200, 500)
while i < n:
x.append(i)
i += 1
currentTime = dt.datetime.now().strftime("%M")
timelist.append(currentTime)
timelist = timelist[-n:]
for i in range(0, n):
timelist[i] = int(timelist[i])
i = n
j = 0
while i > 0:
timelist[i - 1] = timelist[i - 1] - j
if timelist[i - 1] < 0:
timelist[i - 1] = timelist[i - 1] + 60
j += 1
i -= 1
for i in range(0, n):
timelist[i] = str(timelist[i])
H.plot(x, OUT_Buffer_Temperatura,pen=pg.mkPen(
color='#ff0000', width=3))
H.plot(x, OUT_Buffer_Temp_SetPoint,pen=pg.mkPen(
color='#00ff70', width=3))
H.plot(x, OUT_Buffer_Regulator,pen=pg.mkPen(
color='#0000ff', width=3))
H.plot(x, OUT_Buffer_Output,pen=pg.mkPen(
color='y', width=3))
H.setTitle('Temperatura (Rd), Setpoint (Ze), Regulator (Mo), Output (Ru)')
H.showGrid(True, True)
H.setLabel('left', 'Temperatura, Output', units='deg.C, %', **{'font-size':
'20pt'})
H.setLabel('bottom', 'Cas', units='min', **{'font-size': '20pt'})
ticks = list(enumerate(timelist))
ticks = ticks[::5]
ax = H.getAxis("bottom")
ax.setTicks([ticks])
#------------------------------------------------------------------------------
#==============================================================================
def graph_povp_temp_Zu(): # 31 dni
global OUT_Buffer_Povp_Temp_ZU
n = 31
out_buffer_povp_temp_zu = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for i in range(0, n):
out_buffer_povp_temp_zu[i] = OUT_Buffer_Povp_Temp_ZU[i]
Bufer_Povp_Temp_ZU(0, out_buffer_povp_temp_zu)
now = time.time()
timestamps = numpy.linspace(now - 2592000, now, 31)
H = pg.plot()
H.resize(1200, 500)
bg1 = pg.BarGraphItem(x=timestamps-45000, height=out_buffer_povp_temp_zu,
width=50000, brush='b')
axis = DateAxisItem(orientation='bottom')
axis.attachToPlotItem(H.getPlotItem())
H.addItem(bg1)
H.setTitle('Povprecna temperatura zunaj')
H.showGrid(True, True)
H.setLabel('left', 'Temperatura', units='degC', **{'font-size': '20pt'})
H.setLabel('bottom', 'Cas', units='dan', **{'font-size': '20pt'})
#-------------------------------------------------------------------------------
def graph_24h_poraba_kWh(): # 31 dni
global OUT_Buffer_24h_Poraba_kWh
n = 31
out_buffer_24_poraba_kwh = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for i in range(0, n):
out_buffer_24_poraba_kwh[i] = OUT_Buffer_24h_Poraba_kWh[i]
Bufer_24h_Poraba_kWh(0, out_buffer_24_poraba_kwh)
now = time.time()
timestamps = numpy.linspace(now - 2592000, now, 31)
H = pg.plot()
H.resize(1200, 500)
bg1 = pg.BarGraphItem(x=timestamps-45000, height=out_buffer_24_poraba_kwh,
width=50000, brush='r')
axis = DateAxisItem(orientation='bottom')
axis.attachToPlotItem(H.getPlotItem())
H.addItem(bg1)
H.setTitle('Poraba elektricne energije na dan')
H.showGrid(True, True)
H.setLabel('left', 'E. energija', units='kWh/dan', **{'font-size': '20pt'})
H.setLabel('bottom', 'Cas', units='dan', **{'font-size': '20pt'})
#-------------------------------------------------------------------------------
def graph_24h_poraba_voda(): # 31 dni
global OUT_Buffer_24h_Poraba_Voda
n = 31
out_buffer_24_poraba_voda = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for i in range(0, n):
out_buffer_24_poraba_voda[i] = OUT_Buffer_24h_Poraba_Voda [i]
Bufer_24h_Poraba_Voda(0, out_buffer_24_poraba_voda)
now = time.time()
timestamps = numpy.linspace(now - 2592000, now, 31)
H = pg.plot()
H.resize(1200, 500)
bg1 = pg.BarGraphItem(x=timestamps-45000, height=out_buffer_24_poraba_voda,
width=50000, brush='b')
axis = DateAxisItem(orientation='bottom')
axis.attachToPlotItem(H.getPlotItem())
H.addItem(bg1)
H.setTitle('Poraba vode na dan')
H.showGrid(True, True)
H.setLabel('left', 'Poraba vode', units='L/dan', **{'font-size': '20pt'})
H.setLabel('bottom', 'Cas', units='dan', **{'font-size': '20pt'})
#-----------------------------------------------------------------------------
def get_timestamps():
global now_time
now_time = time.time()
#print(now_time)
#------------------------------------------------------------------------------
def graph_24h_poraba_plin(): # 31 dni 1610146864.5722635
global OUT_Buffer_24h_Poraba_Plin
global now_time
now_time = 1610146864.5722635
n = 31
out_buffer_24_poraba_plin = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for i in range(0, n):
out_buffer_24_poraba_plin[i] = OUT_Buffer_24h_Poraba_Plin[i]
Bufer_24h_Poraba_Plin(0, out_buffer_24_poraba_plin)
timestamps_31 = numpy.linspace(now_time - 2592000, now_time, 31)
H = pg.plot()
H.resize(1200, 500)
bg1 = pg.BarGraphItem(x=timestamps_31, height=out_buffer_24_poraba_plin,
width=80000, brush='y')
axis = DateAxisItem(orientation='bottom')
axis.attachToPlotItem(H.getPlotItem())
H.addItem(bg1)
H.setTitle('Poraba plina na dan')
H.showGrid(True, True)
H.setLabel('left', 'Poraba plina', units='m3/dan', **{'font-size': '20pt'})
H.setLabel('bottom', 'Cas (dan)', units=' ', **{'font-size': '20pt'})
def graph_cas_ogrevanja_zg_sp():
global OUT_Buffer_ogrevanje_spodaj, OUT_Buffer_ogrevanje_zgoraj
global OUT_Buffer_ogrevanje_bojler, OUT_Buffer_ogrevanje_drva
global now_time
now_time = 1610146864.5722635
n = 31
out_buffer_ogrevanje_zg = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
out_buffer_ogrevanje_sp = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
out_buffer_ogrevanje_bo = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
out_buffer_ogrevanje_dr = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for i in range(0, n):
out_buffer_ogrevanje_zg[i] = OUT_Buffer_ogrevanje_zgoraj[i]
out_buffer_ogrevanje_sp[i] = OUT_Buffer_ogrevanje_spodaj[i]
out_buffer_ogrevanje_bo[i] = OUT_Buffer_ogrevanje_bojler[i]
out_buffer_ogrevanje_dr[i] = OUT_Buffer_ogrevanje_drva[i]
Bufer_ogrevanje_zgoraj(0, out_buffer_ogrevanje_zg)
Bufer_ogrevanje_spodaj(0, out_buffer_ogrevanje_sp)
Bufer_ogrevanje_bojler(0, out_buffer_ogrevanje_bo)
Bufer_ogrevanje_drva(0, out_buffer_ogrevanje_dr)
#now = time.time()
timestamps = numpy.linspace(now_time - 2592000, now_time, 31)
H = pg.plot()
H.resize(1200, 500)
bg1 = pg.BarGraphItem(x=timestamps-20000, height=out_buffer_ogrevanje_zg,
width=15000, brush='r')
bg2 = pg.BarGraphItem(x=timestamps-5000, height=out_buffer_ogrevanje_sp,
width=15000, brush='b')
bg3 = pg.BarGraphItem(x=timestamps+10000, height=out_buffer_ogrevanje_bo,
width=15000, brush='g')
bg4 = pg.BarGraphItem(x=timestamps+25000, height=out_buffer_ogrevanje_dr,
width=15000, brush='y')
axis = DateAxisItem(orientation='bottom')
axis.attachToPlotItem(H.getPlotItem())
H.addItem(bg1)
H.addItem(bg2)
H.addItem(bg3)
H.addItem(bg4)
H.setTitle('Cas ogrevanja Zgoraj (Rd), Spodaj (Mo), Bojler (Ze), Drva
(Ru)')
H.showGrid(True, True)
H.setLabel('left', 'Cas', units='min', **{'font-size': '20pt'})
H.setLabel('bottom', 'Cas', units='dan', **{'font-size': '20pt'})
#------------------------------------------------------------------------------
def graph_poraba_kWh_3h(): # 3 ure
global OUT_Buffer_kWh_3h
now = time.time()
timestamps = numpy.linspace(now - 10800, now, 181)
H = pg.plot()
H.resize(1500, 500)
axis = DateAxisItem(orientation='bottom')
axis.attachToPlotItem(H.getPlotItem())
H.plot(x=timestamps, y=OUT_Buffer_kWh_3h, pen=pg.mkPen(
'r', width=3))
H.setTitle('Poraba elektricne energije_3h')
H.showGrid(True, True)
H.setLabel('left', 'Poraba e.energije 3h', units='kWh', **{'font-size':
'20pt'})
H.setLabel('bottom', 'Cas', units='min', **{'font-size': '20pt'})