Thursday, 8 November 2018

error - QGIS 3 startup script is not executed


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?



Answer



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


No comments:

Post a Comment