Skip to content

Python3 - Pipenv für die virtuelle Entwicklungsumgebung

Python3
  • Python hat ein wirklich sehr groß entwickeltes Ökosystem, mit ganz vielen Tools, die man erst mal finden muss und dann im zweiten Step auch nutzen können muss.

    Hier geht es heute um pipenv

    01b9dc8f-34ae-4a32-b18a-5e06df39e960-grafik.png

    Installation

    sudo apt install pipenv
    

    Virtuelle Umgebung anlegen

    Wir wechseln ins Projektverzeichnis

    cd /home/$USER/projekt1
    

    Die Entwicklungsumgebung anlegen

    pipenv --python 3.8
    

    Die Entwicklungsumgebung starten

    frank@frank-MS-7C37:~/restic_ui$ pipenv shell
    Spawning environment shell (/bin/bash). Use 'exit' to leave.
    frank@frank-MS-7C37:~/restic_ui$ . /home/frank/.local/share/virtualenvs/restic_ui-RwXjz-0W/bin/activate
    (restic_ui-RwXjz-0W) frank@frank-MS-7C37:~/restic_ui$ pipenv
    Usage: pipenv [OPTIONS] COMMAND [ARGS]...
    
    Options:
      --where          Output project home information.
      --venv           Output virtualenv information.
      --py             Output Python interpreter information.
      --envs           Output Environment Variable options.
      --rm             Remove the virtualenv.
      --bare           Minimal output.
      --completion     Output completion (to be eval'd).
      --man            Display manpage.
      --three / --two  Use Python 3/2 when creating virtualenv.
      --python TEXT    Specify which version of Python virtualenv should use.
      --site-packages  Enable site-packages for the virtualenv.
      --version        Show the version and exit.
      -h, --help       Show this message and exit.
    
    
    Usage Examples:
       Create a new project using Python 3.6, specifically:
       $ pipenv --python 3.6
    
       Install all dependencies for a project (including dev):
       $ pipenv install --dev
    
       Create a lockfile containing pre-releases:
       $ pipenv lock --pre
    
       Show a graph of your installed dependencies:
       $ pipenv graph
    
       Check your installed dependencies for security vulnerabilities:
       $ pipenv check
    
       Install a local setup.py into your virtual environment/Pipfile:
       $ pipenv install -e .
    
       Use a lower-level pip command:
       $ pipenv run pip freeze
    
    Commands:
      check      Checks for security vulnerabilities and against PEP 508 markers
                 provided in Pipfile.
      clean      Uninstalls all packages not specified in Pipfile.lock.
      graph      Displays currently–installed dependency graph information.
      install    Installs provided packages and adds them to Pipfile, or (if none
                 is given), installs all packages.
      lock       Generates Pipfile.lock.
      open       View a given module in your editor.
      run        Spawns a command installed into the virtualenv.
      shell      Spawns a shell within the virtualenv.
      sync       Installs all packages specified in Pipfile.lock.
      uninstall  Un-installs a provided package and removes it from Pipfile.
      update     Runs lock, then sync.
    
  • Ich ko... immer, wenn ich mein VSCodium neu installieren muss. Das größte Problem dabei ist immer, das ich fast immer vergesse den Python Interpreter zu setzen.

    "CTRL+SHIFT+P" and choose the correct python interpreter.

    46f85075-4dbc-414c-94c2-abc5bb6009b6-grafik.png

    Danach startet das Python Programm auch wieder aus der richtigen Entwicklungsumgebung 🙂

  • Python3 - enumerate()

    Python3
    2
    1
    0 Stimmen
    2 Beiträge
    138 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.
  • Python3 - PyQt5 QIcon

    Python3
    2
    2
    0 Stimmen
    2 Beiträge
    152 Aufrufe
    FrankMF
    Die Suchpfade findet man hiermit print(QIcon.themeSearchPaths()) Ausgabe ['/home/frank/.icons', '/usr/share/cinnamon/icons', '/var/lib/flatpak/exports/share/icons', '/usr/share/icons', ':/icons']
  • Django - Webframework

    Python3
    1
    2
    0 Stimmen
    1 Beiträge
    129 Aufrufe
    Niemand hat geantwortet
  • Restic UI - Documentation

    Restic UI
    1
    1
    0 Stimmen
    1 Beiträge
    311 Aufrufe
    Niemand hat geantwortet
  • Python3 - class BackupList

    Python3
    2
    0 Stimmen
    2 Beiträge
    252 Aufrufe
    FrankMF
    Mir hat heute jemand auf Twitter zu meinem Problem geantwortet. https://twitter.com/OliverTheUnique/status/1381888728080211968 Das habe ich natürlich direkt, bei einer Tasse Kaffee, ausprobiert. Geht einwandfrei und ein Problem ist damit Vergangenheit. Bei meiner Konstruktion musste ich immer eine Länge für die Liste p vorgeben. p = list(range(10)) Das wird jetzt nicht mehr benötigt. Schön Jetzt muss ich mir das noch in Ruhe anschauen, nachlesen und verstehen. Danke für den netten Hinweis!
  • Python3 - PyQt5 Layout

    Python3
    1
    2
    0 Stimmen
    1 Beiträge
    185 Aufrufe
    Niemand hat geantwortet
  • Python3 - Globale Variablen

    Python3
    1
    0 Stimmen
    1 Beiträge
    144 Aufrufe
    Niemand hat geantwortet
  • Wireguard UI - mein erstes Python3 Projekt

    Python3
    2
    3
    0 Stimmen
    2 Beiträge
    251 Aufrufe
    FrankMF
    Dinge entwickeln sich. Es sieht alles schon wieder was anders aus Hauptfenster [image: 1600889374694-270b5c68-3d64-44ca-9a01-e3f24ba4a26c-grafik.png] Setup Fenster zum Erstellen der wg0.conf [image: 1600889412743-27c3cb28-50f5-4e00-b03d-de47c07372a0-grafik.png] Und alles funktioniert so weit