1

Following the documentation for QGIS 3 startup script, I have placed a 'startup.py' script in the following path:

C:\Users\Me\AppData\Roaming\QGIS\QGIS3\profiles\default\python\startup.py

But the script does not get executed. The script only contains the following line:

iface.messageBar().pushMessage("Error", "I'm sorry Dave, I'm afraid I can't do that", level=Qgis.Critical)

When QGIS loads, it should come up with an error message complaing about iface not being recognised. But I receive nothing. I can set up the custom variable and point the path to the Python file but I want to use the startup script method.

Any ideas why?

  • 1
    $.02: It is philosophically questionable to have an app startup script - supposed to run only once - in a user profile folder. The last profile that was used will be the one loaded next time QGIS starts, and it may or not contain the script. If we run the script when changing profile as well, it could be ran more than once and after the app has started. – JGH Apr 10 at 0:16
2

QGIS only execute this file if it is put here:

C:\Users\username\AppData\Roaming\QGIS\QGIS3

If we see the Core code: https://github.com/qgis/QGIS/blob/b53d64bfb0b234cbd5a25fd57d9f07f7309e444c/src/python/qgspythonutilsimpl.cpp#L191

This imports the startup.py file and if it is not found here it returns an empty list.

for check it using python:

QStandardPaths.locateAll( QStandardPaths.AppDataLocation, "startup.py" )

enter image description here

maybe the documentation is not correct or is a issue in the code

  • You're right thanks, I guess the documentation hasn't been updated yet. – Joseph Apr 10 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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