Skip to content

Python3 - PyQt6 installieren

Python3
  • Immer wenn ich versuche PyQt6 zu installieren, bekomme ich merkwürdige Fehlermeldungen.

    frank@frank-MS-7C37:~/qsettings$ pipenv install PyQt6
    Installing PyQt6…
    Looking in indexes: https://pypi.python.org/simple
    Collecting PyQt6
      Using cached PyQt6-6.2.2-cp36-abi3-manylinux1_x86_64.whl (7.7 MB)
    
    Error:  An error occurred while installing PyQt6!
    ERROR: Could not find a version that satisfies the requirement PyQt6-Qt6>=6.2.2 (from PyQt6) (from versions: none)
    ERROR: No matching distribution found for PyQt6-Qt6>=6.2.2 (from PyQt6)
    

    Sauber läuft das nur, wenn das Paket pip aktuell ist. Also hier mal eine Vorgehensweise, wie man das sauber installiert.

    env Umgebung bauen

    pipenv --python 3.8
    

    Danach, die Umgebung starten

    frank@frank-MS-7C37:~/qsettings$ pipenv shell
    Spawning environment shell (/bin/bash). Use 'exit' to leave.
    

    pip aktualisieren

    (qsettings-kBmIZW-V) frank@frank-MS-7C37:~/qsettings$ python -m pip install -U pip
    Collecting pip
      Using cached pip-21.3.1-py3-none-any.whl (1.7 MB)
    Installing collected packages: pip
      Attempting uninstall: pip
        Found existing installation: pip 20.0.2
        Uninstalling pip-20.0.2:
          Successfully uninstalled pip-20.0.2
    Successfully installed pip-21.3.1
    

    PyQt6 installieren

    (qsettings-kBmIZW-V) frank@frank-MS-7C37:~/qsettings$ pipenv install PyQt6
    Installing PyQt6…
    Looking in indexes: https://pypi.python.org/simple
    Collecting PyQt6
      Using cached PyQt6-6.2.2-cp36-abi3-manylinux1_x86_64.whl (7.7 MB)
    Collecting PyQt6-sip<14,>=13.2
      Using cached PyQt6_sip-13.2.0-cp38-cp38-manylinux1_x86_64.whl (310 kB)
    Collecting PyQt6-Qt6>=6.2.2
      Using cached PyQt6_Qt6-6.2.2-py3-none-manylinux_2_28_x86_64.whl (50.0 MB)
    Installing collected packages: PyQt6-sip, PyQt6-Qt6, PyQt6
    Successfully installed PyQt6-6.2.2 PyQt6-Qt6-6.2.2 PyQt6-sip-13.2.0
    
    Adding PyQt6 to Pipfile's [packages]…
    Pipfile.lock not found, creating…
    Locking [dev-packages] dependencies…
    Locking [packages] dependencies…
    Updated Pipfile.lock (7f928c)!
    Installing dependencies from Pipfile.lock (7f928c)…
      🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 3/3 — 00:00:00
    

    Danach meckert auch nicht mehr, wenn ich ein PyQt6 Modul importieren möchte

    from PyQt6.QtCore import QSettings
    
  • FrankMF FrankM hat am auf dieses Thema verwiesen

  • 0 Stimmen
    1 Beiträge
    52 Aufrufe
    Niemand hat geantwortet
  • Python - Dict -> JSON und umgekehrt

    Python3
    1
    0 Stimmen
    1 Beiträge
    173 Aufrufe
    Niemand hat geantwortet
  • Python - Match-Case Statement

    Python3
    1
    0 Stimmen
    1 Beiträge
    82 Aufrufe
    Niemand hat geantwortet
  • Python3 - enumerate()

    Python3
    2
    0 Stimmen
    2 Beiträge
    88 Aufrufe
    FrankMF

    Ich habe noch was Code gefunden, den ich mal dringend aufräumen musste 🙂 Wenn ich mit dem Restic UI die Snapshots anzeige, dann sieht das so aus.

    reading repository password from stdin ID Time Host Tags Paths ---------------------------------------------------------------------------- 4e769748 2021-12-31 21:48:34 frank-MS-7C37 /home/frank/Bilder 34298934 2022-01-26 20:15:53 frank-MS-7C37 /home/frank/Bilder 0d5d88f2 2022-01-27 21:05:07 frank-MS-7C37 /home/frank/Bilder f0e7d5a7 2022-01-29 13:46:12 frank-MS-7C37 /home/frank/Bilder 79918d70 2022-01-29 13:52:56 frank-MS-7C37 /home/frank/Bilder d74272a3 2022-01-30 11:54:20 frank-MS-7C37 /home/frank/Bilder 11b0b5ad 2022-01-30 11:57:44 frank-MS-7C37 /home/frank/Bilder 4a7450d2 2022-02-20 09:35:56 frank-MS-7C37 /home/frank/Bilder c1a4a51d 2022-02-20 09:36:43 frank-MS-7C37 /home/frank/Bilder d178ded5 2022-02-20 09:38:53 frank-MS-7C37 /home/frank/Bilder 997e2259 2022-02-20 16:35:57 frank-MS-7C37 /home/frank/Bilder 3320ad5c 2022-02-20 16:49:19 frank-MS-7C37 /home/frank/Bilder ---------------------------------------------------------------------------- 12 snapshots

    Mich interessieren die IDs, weil ich bei der Eingabe der IDs überprüfen möchte, ob die eingegebene ID existiert. Also muss ich das irgendwie auslesen und speichern. Das habe ich bis jetzt so gemacht.

    def id_append(self, result): # We split the result into individual lines. # Result was passed. And create an list. result_list = result.split('\n') # We count the number of repositories and search for 'source'. count = result.count(backup_data[row].source) # Offset added, first interesting line is line 3! count = count + 3 # We loop through the list and output the ID's and store in snapshot_id x = 3 while x < count: a = result_list[x] y = a[0:8] snapshot_id.append(y) x = x + 1

    Das erschien mir heute, beim erneuten Betrachten, Spaghetticode zu sein. Machen wir das mal etwas ordentlicher.

    Ich nehme die Ausgabe (stdout) und erzeuge eine Liste, jede Zeile ein Element.

    result_list = result.split('\n')

    Sieht so aus

    ['reading repository password from stdin', 'ID Time Host Tags Paths', '----------------------------------------------------------------------------', '4e769748 2021-12-31 21:48:34 frank-MS-7C37 /home/frank/Bilder', '34298934 2022-01-26 20:15:53 frank-MS-7C37 /home/frank/Bilder', '0d5d88f2 2022-01-27 21:05:07 frank-MS-7C37 /home/frank/Bilder', 'f0e7d5a7 2022-01-29 13:46:12 frank-MS-7C37 /home/frank/Bilder', '79918d70 2022-01-29 13:52:56 frank-MS-7C37 /home/frank/Bilder', 'd74272a3 2022-01-30 11:54:20 frank-MS-7C37 /home/frank/Bilder', '11b0b5ad 2022-01-30 11:57:44 frank-MS-7C37 /home/frank/Bilder', '4a7450d2 2022-02-20 09:35:56 frank-MS-7C37 /home/frank/Bilder', 'c1a4a51d 2022-02-20 09:36:43 frank-MS-7C37 /home/frank/Bilder', 'd178ded5 2022-02-20 09:38:53 frank-MS-7C37 /home/frank/Bilder', '997e2259 2022-02-20 16:35:57 frank-MS-7C37 /home/frank/Bilder', '3320ad5c 2022-02-20 16:49:19 frank-MS-7C37 /home/frank/Bilder', '----------------------------------------------------------------------------', '12 snapshots', '']

    Diesmal benutzen wir die enumerate() Funktion

    for count, value in enumerate(result_list): print(count, value)

    Das was raus kommt, sieht so aus

    0 reading repository password from stdin 1 ID Time Host Tags Paths 2 ---------------------------------------------------------------------------- 3 4e769748 2021-12-31 21:48:34 frank-MS-7C37 /home/frank/Bilder 4 34298934 2022-01-26 20:15:53 frank-MS-7C37 /home/frank/Bilder 5 0d5d88f2 2022-01-27 21:05:07 frank-MS-7C37 /home/frank/Bilder 6 f0e7d5a7 2022-01-29 13:46:12 frank-MS-7C37 /home/frank/Bilder 7 79918d70 2022-01-29 13:52:56 frank-MS-7C37 /home/frank/Bilder 8 d74272a3 2022-01-30 11:54:20 frank-MS-7C37 /home/frank/Bilder 9 11b0b5ad 2022-01-30 11:57:44 frank-MS-7C37 /home/frank/Bilder 10 4a7450d2 2022-02-20 09:35:56 frank-MS-7C37 /home/frank/Bilder 11 c1a4a51d 2022-02-20 09:36:43 frank-MS-7C37 /home/frank/Bilder 12 d178ded5 2022-02-20 09:38:53 frank-MS-7C37 /home/frank/Bilder 13 997e2259 2022-02-20 16:35:57 frank-MS-7C37 /home/frank/Bilder 14 3320ad5c 2022-02-20 16:49:19 frank-MS-7C37 /home/frank/Bilder 15 ---------------------------------------------------------------------------- 16 12 snapshots 17

    Mich interessieren nur die Zeilen mit /home/frank/Bilder Das kann man so abfragen

    if backup_data[row].source in value:

    Und jetzt nur die ID entsprechend abspeichern

    snapshot_id.append(value[0:8])

    Sieht jetzt komplett so aus

    result_list = result.split('\n') for count, value in enumerate(result_list): if backup_data[row].source in value: snapshot_id.append(value[0:8]) print(count, value[0:8])

    Somit speichert er jetzt nur noch die IDs, der folgenden Ausgabe.

    3 4e769748 4 34298934 5 0d5d88f2 6 f0e7d5a7 7 79918d70 8 d74272a3 9 11b0b5ad 10 4a7450d2 11 c1a4a51d 12 d178ded5 13 997e2259 14 3320ad5c

    Diese IDs, kann ich dann weiterverarbeiten.

  • 0 Stimmen
    2 Beiträge
    207 Aufrufe
    FrankMF

    Der Autor hat meine Anpassungen um ein paar Änderungen erweitert und in sein Repo eingepflegt. Der QtWaitingSpinenr ist jetzt auch 3.10 kompatibel 🤓

    1b268980-92ca-42a4-89a0-a6e4b7ab9378-grafik.png

  • PyQt5 - QThread

    Python3
    3
    0 Stimmen
    3 Beiträge
    140 Aufrufe
    FrankMF

    Und hier mal ein komplettes Beispiel.

    class Worker

    Wir legen den Worker an, das ist der Prozess der die Arbeit macht und etwas länger braucht.

    class Worker(QObject): """ Worker Class for Rest function stats""" stats_finished = pyqtSignal(str) stats_error = pyqtSignal(str) def __init__(self): super().__init__() def run(self): # Restic function try: # long running task except Exception: # Process don't successful, send signal self.stats_error.emit(result.stderr) else: # Process successful, send signal self.stats_finished.emit(result.stdout) finally: pass in class MainWindow class MainWindow(QMainWindow): def __init__(self): super().__init__() "First Thread with documentation" # Worker for restic_stats # Create a QThread object self.thread = QThread() # Create a worker object self.worker1 = Worker() # Move worker to the thread self.worker1.moveToThread(self.thread) # Connect signals and slots self.thread.started.connect(self.worker1.run) self.worker1.stats_finished[str].connect(self.restic_stats_finished) self.worker1.stats_error[str].connect(self.restic_stats_error) "First thread end" ############################################### # Process for restic_stats is finished ############################################### @pyqtSlot(str) def restic_stats_finished(self, i): # Signal from worker thread without an error Spinner.stop(self) self.thread.quit() ############################################### # Process for restic_stats when get an error ############################################### @pyqtSlot(str) def restic_stats_error(self, i): # Signal from worker thread with an error! Spinner.stop(self) Funktion restic_stats def restic_stats(self): # we start the worker thread self.thread.start() # we start waitingspinnerwidget Spinner.start(self)

    Ich wollte gerade schreiben, das folgendes sehr wichtig ist

    self.thread.quit()

    da fällt mir ein Fehler auf. Kurz ausprobiert und bingo, wenn der Prozess einen Error triggert, muss natürlich auch der Prozess beendet werden. Wenn man das nicht macht, macht das Programm nicht das was es soll. Der Grund ist, das der Prozess einfach immer weiter läuft. Er MUSS beendet werden. Ich gehe dann mal in meinem Programm alles ändern 🙂

    Ok, jetzt geht die Funktion auch zweimal hintereinander und gibt auch ordentlich den Fehler aus.

    Fazit

    Ich habe wieder sehr viel gelernt und hoffe das ich es auch richtig verstanden habe 😉 Hoffe das es dem ein oder anderen Anfänger hilft. Und falls hier ein Profi mitliest und hier Blödsinn steht bitte ich um einen Kommentar, damit ich das ändern kann. Es steht schon genug Blödsinn im Netz 🙂

  • Restic UI - Changelog

    Angeheftet Restic UI
    3
    0 Stimmen
    3 Beiträge
    261 Aufrufe
    FrankMF

    v1.5.0 - Release for restic v0.14.0 with compression and migration tool

  • Restic UI - User documentation

    Restic UI
    1
    0 Stimmen
    1 Beiträge
    213 Aufrufe
    Niemand hat geantwortet