Pycharm – die besten Beiträge

Raspberry PI Flask-404 Not Found?

Hallo!

Ich habe das programmiert. Es wird jede Sekunde die Temperatur von der CPU ausgelesen. Jetzt möchte ich Flask einbauen, damit ich mit mehreren PC's darauf zugreifen kann. Aber es funktioniert nicht. Warum?

from flask import Flask, jsonify
import subprocess
import time
import os
from colorama import Fore, Style

app = Flask(__name__)

@app.route("/temp")
def get_cpu_temperature():
  try:
    result = subprocess.run(['vcgencmd', 'measure_temp'], capture_output=True, text=True, check=True)
    temperature_str = result.stdout.strip()
    temperature = float(temperature_str[5:-2]) # Extrahiere die Temperatur aus dem String
    return temperature
  except subprocess.CalledProcessError as e:
    print(f"Fehler beim Ausführen des Befehls: {e}")
    return None

def print_colored_temperature(temperature):
  if temperature is not None:
    if temperature > 49.9:
      print(f"{Fore.RED}Temperatur: {temperature}°C{Style.RESET_ALL}")
    else:
      print(f"Temperatur: {temperature}°C")
  else:
    print("Fehler beim Lesen der CPU-Temperatur.")

def main():
  try:
    while True:
      temperature = get_cpu_temperature()
      print_colored_temperature(temperature)
      time.sleep(1)
      os.system('clear')
  except KeyboardInterrupt:
    print("Programm wurde durch den Benutzer unterbrochen.")
  except Exception as e:
    print(f"Ein Fehler ist aufgetreten: {e}")
     
     


if __name__ == '__main__':
  app.run(host="0.0.0.0")

if __name__ == '__main__':
  main()
  import sys
  sys.exit(main(sys.argv))  
HTML, Code, Programmiersprache, Python, Python 3, Pycharm, Discord, Flask, Discord Bot, ChatGPT

Python Fehler no attribute 'TFE_NewContextOptions'?

Hi, Ich habe einen Fehler beim ausführen von einem Python Script:

C:\Users\DeneX\Desktop\SC_FEGAN\SC-FEGAN-program-files>python demo.py

Traceback (most recent call last):

 File "C:\Users\DeneX\Desktop\SC_FEGAN\SC-FEGAN-program-files\demo.py", line 11, in <module>

   from model import Model

 File "C:\Users\DeneX\Desktop\SC_FEGAN\SC-FEGAN-program-files\model.py", line 1, in <module>

   import tensorflow as tf

 File "C:\Users\DeneX\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\tensorflow\__init__.py", line 24, in <module>

   from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import

   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 File "C:\Users\DeneX\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\tensorflow\python\__init__.py", line 49, in <module>

   from tensorflow.python import pywrap_tensorflow

 File "C:\Users\DeneX\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>

   from tensorflow.python.pywrap_tensorflow_internal import *

 File "C:\Users\DeneX\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 96, in <module>

   TFE_NewContextOptions = _pywrap_tensorflow_internal.TFE_NewContextOptions

                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

AttributeError: module '_pywrap_tensorflow_internal' has no attribute 'TFE_NewContextOptions'

Wie bekomme ich das behoben; Ich habe tensorflow==1.13.0rc2 installiert damit das Script läuft & Python 3.11.3

Linux, Programmiersprache, Python, Python 3, Pygame, Tkinter, Pycharm, Discord, Discord Bot

Meistgelesene Beiträge zum Thema Pycharm