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 🙂

  • Python - Frameworks

    Python3
    2
    0 Stimmen
    2 Beiträge
    76 Aufrufe
    FrankMF

    Und mal hier parken

  • Python - Dict -> JSON und umgekehrt

    Python3
    1
    0 Stimmen
    1 Beiträge
    191 Aufrufe
    Niemand hat geantwortet
  • Python3 - pyqtSignal

    Python3
    1
    0 Stimmen
    1 Beiträge
    66 Aufrufe
    Niemand hat geantwortet
  • 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 🙂

  • Django - Webframework

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

    Restic UI
    1
    0 Stimmen
    1 Beiträge
    206 Aufrufe
    Niemand hat geantwortet
  • Python3 - Umzug nach Fedora 34

    Python3
    1
    0 Stimmen
    1 Beiträge
    145 Aufrufe
    Niemand hat geantwortet
  • Python und GUI

    Verschoben Python3
    1
    0 Stimmen
    1 Beiträge
    155 Aufrufe
    Niemand hat geantwortet