Skip to content

Python3

Ihr sprecht Python? 😉 Ich übe noch..

71 Topics 133 Posts

Subcategories


  • Low code Python web framework

    7 Topics
    18 Posts
    FrankMF

    Und solltest Du was finden, was kaputt ist, ich freue mich immer über Feedback 😉

  • Mein zweites Python & PyQT5 Projekt

    13 Topics
    27 Posts
    FrankMF

    Mit der Einführung der Kompression in Restic v0.14.0 ist das Verlangen groß auch zu sehen, welche Version das Repo hat. E gibt die alte Version v1 und die neue mit Kompression v2.

    Das hat mich natürlich auch interessiert und es gibt da auch keine direkte Anzeigemöglichkeit für. Im Forum wurde mir dann geraten, das mit

    restic cat config

    zu machen. Das habe ich nun so eingebaut, das in der Übersicht die Version angezeigt wird. Da das je nach Ort des Repos ein wenig dauern kann, habe ich die Funktion als QThread integriert mit dem bekannten Spinner.

    b3f1ed1a-b943-4d90-9f8b-70aba9a9eed6-grafik.png

  • Mein Restic Webinterface, gebaut mit Python & Flask

    1 Topics
    1 Posts
    FrankMF

    Ich habe ja damals mit PyWebIO ein Restic UI gebaut. Das gibt es auch auf gitlab.com

    Dieses PyWebIO ist schon ein tolles Tool, weil man den Python Code nicht verlässt. Aber, es hat zu viele Einschränkungen, die man dann nicht, oder nur sehr mühsam umgehen kann. Also war ich auf der Suche nach neuen Herausforderungen 🙂

    Zwei Frameworks die ich kannte, waren Django und Flask. Meine Wahl fiel auf Flask. Und nun fand ich mich wieder in Dingen, die ich vor langer Zeit zuletzt benutzt hatte. HTML, CSS und Javascript. Ich musste mich also wieder durch viele Themengebiete wühlen. Dank der Hilfe von ChatGPT, der mir einiges wieder erklären musste, habe ich dann aber mein Tool wieder so hinbekommen, wie ich es gerne haben wollte.

    Ich wollte es heute mal anhand einiger Screenshots vorstellen. Die Funktionalität ist wie beim alten Tool. Habe es aber ein wenig angepasst und viel mehr Funktionen ins Dashboard gepackt. Somit ist von dort aus, fast alles zu erreichen.

    Dashboard

    dashboard.png

    Dashboard mit Hamburger Menü

    hamburger_menue.png

    Add Backup

    add_backup.png

    Add Backup with REST

    add_backup_with_REST.png

    Edit Backup

    edit_backup.png

    About

    about.png

    Allgemeines

    Das Tool ist unter

    https://127.0.0.1:5050/dashboard

    mit selbstsignierten Zertifikaten erreichbar.

    Restic UI Flask nutzt als Backend zur Datenspeicherung eine Redis Datenbank. Ja, ist etwas auf mich zugeschnitten, ich habe hier immer eine Redis DB laufen, noch für andere Sachen.

    ToDo

    Den Code sauber machen, da liegt noch zu viel Müll rum. Danch werde ich den, wenn ich alles nochmal auf Fehler geprüft habe, auf Gitlab veröffentlichen. Vielleicht hilft es dem ein oder anderen 😉

    Ich mach mal mit OBS ein Video davon.

  • Example Class

    Pinned
    3
    0 Votes
    3 Posts
    103 Views
    FrankMF

    In meinem PywebIO Projekt tauchte heute ein alter Bekannter auf. Wenn ich einen Eintrag (innerhalb der Liste) löschte, war das etwas durcheinander 🤔

    Ja, den Fehler kenne ich schon was länger und stolper immer mal wieder drüber. Heute z.B.

    Also mal grübeln 🤓

    Das mache ich, wenn ich einen Eintrag lösche

    case 'Yes': # delete entrie BackupList.delete((line - 1)) # save json BackupList.save_json() # Load data from filesystem BackupList.load_json() # Reload Tab Backup backup()

    Ich mache folgendes

    lösche den Eintrag speicher die Liste lade die Liste baue den Tab wieder auf

    Das führt aber dazu, das meine Liste die als Objekt im Speicher steht nicht aktuell ist. Im Gegenteil, da ist dann etwas Unordnung. Ich brauchte also die Möglichkeit mein Objekt backups irgendwie zurückzusetzen.

    Mal gegoogelt und die Dinge sind manchmal wirklich total easy 🙂

    # clear dict backups.clear()

    Das leert das Objekt und im nächsten Schritt kann ich es wieder befüllen.

    Lösung case 'Yes': # delete entrie BackupList.delete((line - 1)) # save json BackupList.save_json() # clear dict backups.clear() # Load data from filesystem BackupList.load_json() # Reload Tab Backup backup()

    Problem erledigt. Damit ich das noch finde, wenn mein Kopf das nicht mehr hergibt, notiere ich das hier.

  • Flake8 - settings.json

    Pinned
    2
    0 Votes
    2 Posts
    113 Views
    FrankMF

    Das o.g. würde dann für jedes Projekt gelten. Man kann das aber auch Projekt bezogen einstellen. z.B.: mein Restic UI Projekt

    /home/frankm/restic-ui-public/.vscode/

    Da eine Datei settings.json rein.

    { "python.linting.flake8Enabled": true, "python.linting.enabled": true, "python.linting.flake8Args": [ "--ignore=E501", ] ] }
  • Python3 - virtuelle Entwicklungsumgebung

    Pinned
    3
    0 Votes
    3 Posts
    301 Views
    FrankMF

    Nach Systemwechsel erneut Probleme. Hier noch mal aufgelistet.

    Aufpassen, das kein venv Ordner vorhanden ist! Neu anlegen!

    python3 -m venv venv

    Dann meckert mein Linux Mint Cinnamon

    The virtual environment was not created successfully because ensurepip is not available. On Debian/Ubuntu systems, you need to install the python3-venv package using the following command. apt install python3.8-venv You may need to use sudo with that command. After installing the python3-venv package, recreate your virtual environment. Failing command: ['/home/frank/Restic_UI_Produktiv/restic-ui-public/venv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

    Ok, das ist einfach 😉

    apt install python3.8-venv python3 -m venv venv

    Danach aktivieren

    source venv/bin/activate Installation von PyQt5 (venv) frank@frank-MS-7C37:~/Restic_UI_Produktiv/restic-ui-public$ pip3 install PyQt5 Collecting PyQt5 Downloading PyQt5-5.15.4-cp36.cp37.cp38.cp39-abi3-manylinux2014_x86_64.whl (8.3 MB) |████████████████████████████████| 8.3 MB 1.7 MB/s Collecting PyQt5-Qt5>=5.15 Downloading PyQt5_Qt5-5.15.2-py3-none-manylinux2014_x86_64.whl (59.9 MB) |████████████████████████████████| 59.9 MB 18.3 MB/s Collecting PyQt5-sip<13,>=12.8 Downloading PyQt5_sip-12.9.0-cp38-cp38-manylinux1_x86_64.whl (332 kB) |████████████████████████████████| 332 kB 46.1 MB/s Installing collected packages: PyQt5-Qt5, PyQt5-sip, PyQt5 Successfully installed PyQt5-5.15.4 PyQt5-Qt5-5.15.2 PyQt5-sip-12.9.0

    Danach meckert er über ein fehlendes Modul requests

    (venv) frank@frank-MS-7C37:~/Restic_UI_Produktiv/restic-ui-public$ python3 restic_ui.py Traceback (most recent call last): File "restic_ui.py", line 41, in <module> from functions import ( File "/home/frank/Restic_UI_Produktiv/restic-ui-public/functions.py", line 19, in <module> import requests as req ModuleNotFoundError: No module named 'requests' Installation requests (venv) frank@frank-MS-7C37:~/Restic_UI_Produktiv/restic-ui-public$ pip3 install requests Collecting requests Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB) |████████████████████████████████| 61 kB 802 kB/s Collecting chardet<5,>=3.0.2 Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB) |████████████████████████████████| 178 kB 2.7 MB/s Collecting certifi>=2017.4.17 Downloading certifi-2021.5.30-py2.py3-none-any.whl (145 kB) |████████████████████████████████| 145 kB 14.0 MB/s Collecting idna<3,>=2.5 Downloading idna-2.10-py2.py3-none-any.whl (58 kB) |████████████████████████████████| 58 kB 9.4 MB/s Collecting urllib3<1.27,>=1.21.1 Downloading urllib3-1.26.6-py2.py3-none-any.whl (138 kB) |████████████████████████████████| 138 kB 11.5 MB/s Installing collected packages: chardet, certifi, idna, urllib3, requests Successfully installed certifi-2021.5.30 chardet-4.0.0 idna-2.10 requests-2.25.1 urllib3-1.26.6

    Und schwupps, geht mein Tool wieder 🙂

    4968ce42-7c66-4c8a-a2ad-424b9a529d87-grafik.png

  • Wichtige Information!

    Pinned
    1
    0 Votes
    1 Posts
    178 Views
    No one has replied
  • Wichtige Links

    Pinned
    1
    0 Votes
    1 Posts
    170 Views
    No one has replied
  • 0 Votes
    1 Posts
    52 Views
    No one has replied
  • PyWebIO vs. Flask

    2
    0 Votes
    2 Posts
    87 Views
    FrankMF

    Mist, jetzt habe ich auch noch Streamlit gefunden. Jetzt geht mir langsam die Zeit aus...

  • 0 Votes
    5 Posts
    128 Views
    FrankMF

    Hab ChatGPT nochmal nach der Installation auf einem Production Server befragt.

    ChatGPT

    Certainly! Here's a short example of the steps you can follow to deploy a Flask application on a production server using Nginx and Gunicorn:

    Prepare your server:

    Set up a server (e.g., using a cloud provider like AWS, DigitalOcean, or a dedicated server) and ensure it has a clean, up-to-date installation of a Linux distribution (e.g., Ubuntu or CentOS).

    Install required software:

    Install necessary software packages on your server. You'll need Python, pip (Python package manager), Nginx, and Gunicorn. You can use your distribution's package manager (e.g., apt for Ubuntu or yum for CentOS) to install these dependencies.

    Deploy your Flask application:

    Copy your Flask application code and any required dependencies to your server.

    Set up a virtual environment (optional but recommended):

    Create a virtual environment for your Flask application to isolate its dependencies. You can use venv or virtualenv for this purpose.

    Install Flask and any required Python packages within your virtual environment:

    pip install flask

    Test your Flask application:

    Ensure your Flask application runs correctly within your server's virtual environment.

    Configure Gunicorn:

    Create a Gunicorn configuration file (e.g., gunicorn_config.py) to specify the settings for running your Flask application. Here's a simple example: workers = 4 # Number of Gunicorn worker processes bind = '0.0.0.0:8000' # The address and port Gunicorn should listen on

    Start Gunicorn:

    Start Gunicorn with your Flask application: gunicorn -c gunicorn_config.py your_app:app

    Configure Nginx:

    Create an Nginx server block (often located in /etc/nginx/sites-available) to define how Nginx should handle incoming requests. Here's a simplified example: server { listen 80; server_name your_domain.com www.your_domain.com; location / { proxy_pass http://127.0.0.1:8000; # Pass requests to Gunicorn proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } }

    Enable the Nginx server block and restart Nginx:

    sudo ln -s /etc/nginx/sites-available/your_config /etc/nginx/sites-enabled/ sudo nginx -t # Test Nginx configuration sudo systemctl restart nginx

    Configure your DNS:

    Point your domain name to your server's IP address.

    Secure your server (optional but recommended):

    Set up SSL/TLS certificates for your domain to enable HTTPS. You can use Let's Encrypt for free SSL certificates.

    Monitor your application:

    Set up monitoring tools and logs to keep track of your application's performance and troubleshoot any issues.

    These are the basic steps to deploy a Flask application on a production server with Nginx and Gunicorn. Please note that this is a simplified example, and there are many additional considerations, such as database configuration, security, and optimization, depending on your specific application and requirements. It's also important to keep your server and software up to date and follow security best practices to ensure the stability and security of your production environment.

    Das werde ich doch mal ausprobieren 😎

  • 0 Votes
    1 Posts
    66 Views
    No one has replied
  • Ruff - Linting

    1
    0 Votes
    1 Posts
    58 Views
    No one has replied
  • Python - Formatumwandlung str -> float

    1
    0 Votes
    1 Posts
    138 Views
    No one has replied
  • Python - Frameworks

    2
    0 Votes
    2 Posts
    76 Views
    FrankMF

    Und mal hier parken

  • List comprehensions

    1
    0 Votes
    1 Posts
    54 Views
    No one has replied
  • Python - Dict -> JSON und umgekehrt

    1
    0 Votes
    1 Posts
    173 Views
    No one has replied
  • Restic UI - PyWebIO

    3
    0 Votes
    3 Posts
    237 Views
    FrankMF

  • Python - Match-Case Statement

    1
    0 Votes
    1 Posts
    82 Views
    No one has replied
  • Python3 - VSCodium Language Settings

    3
    0 Votes
    3 Posts
    104 Views
    FrankMF

    Ich habe da jetzt gestern stundenlang mit rum gespielt, insbesondere Deinstallation, Neuinstallation, VSCode Installation usw. Das ging einfach nicht.

    Irgendwo meine ich dann gelesen zu haben, das VSCode auf python 3.9 festgenagelt ist und deswegen so einige Dinge nicht gehen.

    Nagelt mich darauf nicht fest, ich bin in dieser Coding Welt kein Profi.

    Dann fiel mir ein, das ich schon vor einigen Monaten mal kurz einen Blick in Pycharm geworfen hatte. Gefiel mir damals gar nicht.

    Das habe ich heute mal auf die Platte geworfen um zu schauen, ob das vernünftig mit dem o.g. Problem umgehen kann.

    6f1c3906-05a3-4126-81d4-7fdf6aa27faa-grafik.png

    Puuuh, da kann man ja noch viel mehr einstellen als bei VSCode, oder mindestens ähnlich viel. Das kann einen ganz schön überfordern. Also Stück für Stück die nächsten Tage.

    Was ist mir positiv aufgefallen?

    Wenn ich VSCodium neu installiert habe, habe ich unheimlich mit Python Versionen, pipenv usw. zu kämpfen gehabt. Bis da mein Projekt wieder lief, konnte schon mal was Zeit vergehen.

    Mit Pycharm Ordner ausgewählt, angeklickt das man dem Coder vertraut. Noch eine Python Version ausgewählt, danach fragt er das er eine pipenv Umgebung gefunden hat und diese nutzen möchte. Ja angeklickt und fertig. Keine zwei Minuten und das Projekt lief wieder 🤓

    Erster Git Commit ging auch sofort und ohne Murren.

    Schon mal ganz viele Pluspunkte gesammelt.

    Was mich aktuell beschäftigt, ist der Tab Problems, da hatte ich vorher deutlich weniger. Da muss ich mich noch was einarbeiten und schauen, wo man das alles einstellen kann.

    Ich halte euch auf dem Laufenden..

    Vielleicht fliegt ja das VSCo** Zeug runter!? Mal sehen..

  • 0 Votes
    2 Posts
    265 Views
    FrankMF

    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 - pyqtSignal

    1
    0 Votes
    1 Posts
    66 Views
    No one has replied
  • Python - mehrsprachiges GUI

    1
    0 Votes
    1 Posts
    111 Views
    No one has replied