0

I'm encountering a persistent issue in my QGIS environment where Processing Algorithms fail to run after the second execution, consistently showing an "Algorithm not found" error. This happens even for standard algorithms provided by QGIS and not just custom scripts.

In Detail: On the first run of my script, I execute Processing Algorithms, such as "qgis:hillshade," successfully. On the second run executing the same algorithm (or any other Processing Algorithm) I consistently get the error message: "Algorithm not found." I make no changes to my QGIS environment, the algorithm itself, or the data. I don't know why the algorithms suddenly become inaccessible.

This problem occurs since I added a code to open a custom parameter selection dialog. I think the code shouldn't interfere with the availability of standard QGIS Processing Algorithms, but if I comment this part, the script runs fine every time. So I guess the code somehow messes with my environment. I tried with fresh environment and checked the Python executable path used by QGIS, which in both cases is the same. After the second execution I tried running the algorithm using the toolbox which worked. I copied the code from processing history and tried running the same algorithm with the interpreter and I get the same error again.

What could be causing this issue? Is there a way to troubleshoot and resolve this error?

i use Mac 12.6.6 and my QGIS Version is 3.22.5-Białowieża.

from qgis.PyQt.QtWidgets import QApplication, QDialog, QLabel, QVBoxLayout, QPushButton, QComboBox

# Create a custom dialog
class ParameterSelectionDialog(QDialog):
    def __init__(self, parent=None):
        super(ParameterSelectionDialog, self).__init__(parent)
        self.setWindowTitle("Parameter Selection")

        layout = QVBoxLayout()

        # Explanation labels for parameters
        explanations = {
            "d0": "choose snowdepth, return periode, dirftsnow ",
            "fillsink": "choose if pcm should fillsink in DTM",
            "avalanche": "choose Avalanche Size"
        }

        for param, explanation in explanations.items():
            label = QLabel(f"{explanation}:")
            layout.addWidget(label)

            # Dropdown menu for parameter values
            combo_box = QComboBox()
            if param == "d0":
                combo_box.addItems(["d0", "d0_30", "d0_50", "d0100", "d0100_30", "d0100_50","d0300", "d0300_30", "d300_50" ])
            elif param == "fillsink":
                combo_box.addItems(["Y", "N"])
            elif param == "avalanche":
                combo_box.addItems(["XL", "L", "M", "XS"])
            layout.addWidget(combo_box)

        close_button = QPushButton("Close")
        close_button.clicked connect(self.accept)
        layout.addWidget(close_button)

        self.setLayout(layout)

# Create the application and show the dialog
app = QApplication([])
dialog = ParameterSelectionDialog()
dialog.exec_()

1 Answer 1

1

If you are running your script inside the QGIS application then you need to remove the line

app = QApplication([])

Otherwise, it will override the current instance of QGIS which breaks links inside the application.

Not sure why exactly it doesn't do it on the first run but it happened multiple times to me and it usually is because of this type of error.

If you want to know how to create a standalone script (run outside of QGIS) check out the documentation

Also not sure if it is a typo but

close_button.clicked connect(self.accept) 

is missing a dot and should be

close_button.clicked.connect(self.accept)
1
  • Thank you @Louis Cottereau!! Now it runs again:)
    – Simon
    Nov 8, 2023 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.