The following is the only the beginning of my script but this is where the problem is located. It runs fine the first time, but break the second time I try running it. I am running the script directly in the QGIS(3.38) python console. There is not problem with the import part of the code only the code after that and I don't know why. I am getting no error message or anything
import sys
from qgis.core import QgsApplication
# Initialize QGIS Application
try:
# Adjust the path to your QGIS installation
QgsApplication.setPrefixPath("C:/Program Files/QGIS 3.38.0", True)
#also tried the file path: C:/Program Files/QGIS 3.38.0/apps/qgis
qgs = QgsApplication([], False)
qgs.initQgis()
print("QGIS application initialized successfully.")
except Exception as e:
print(f"Error initializing QGIS: {e}")
# Properly exit QGIS application
try:
qgs.exitQgis()
print("QGIS application exited successfully.")
except Exception as e:
print(f"Error exiting QGIS: {e}")