3

I would like to use a startup.py which is part of a rollout and not located inside the users config-folder (like ~/.qgis2).

Plugins located in the apps folder (e.g. C:\OSGeo4W64\apps\qgis-ltr\python) are working but if I try to use a startup.py in this folder it isn't executed.

Is there something I can do to get this startup.py executed or is this a bug?

Thomas B
  • 8,807
  • 1
  • 21
  • 62
  • check this https://gis.stackexchange.com/questions/194055/script-that-runs-automatically-from-the-qgis-python-console-when-qgis-starts-us – Fran Raga Sep 24 '18 at 06:26
  • @FranciscoRaga: thanks for the link but this answers do not help to answer my question. The startup.py itself is correct and working if I put it in the users folders. My question is just why it is not executed when put into the python folder of the QGIS install.(If this path is C:\Program Files\QGIS\python, C:\OSGeo4W64\apps\qgis-ltr\python or something else depends on the installer and the choice of the user during installation – Thomas B Sep 24 '18 at 06:48
  • ah okey,then check this,using startup.py outside user folder ,Is the same question asked by you?, https://gis.stackexchange.com/questions/283317/can-i-use-a-startup-py-in-qgis-which-is-stored-outside-the-user-folder/296202 – Fran Raga Sep 24 '18 at 07:05
  • @FranciscoRaga: the linked question answeres the question how to start python code during startup with the --code option but not why a startup.py is not executed when put in the python folder of the QGIS programm folder. – Thomas B Sep 24 '18 at 08:17
  • 1
    Qgis auto execute startup.py in user folder not in other folder,is programmed like this,if you want that execute need add this file to sys path https://gis.stackexchange.com/a/263448/49538 – Fran Raga Sep 24 '18 at 08:38

1 Answers1

1

QGIS does only execute core python plugins from this folder and these plugins can't be extended. Try to store a plugin there, it will not be touched by qgis.

Even if this would be possible, a simple startup.py does not fulfill the requirements of a plugin, which has the structure of a python package, which means it consists of a folder whith file init.py, a function named classFactory and more, described in the pyqgis developer cookbook

At least there is a chance to have a "system wide startup.py" by opening a QGIS-Ticket as a feature request.

Andreas Müller
  • 2,622
  • 13
  • 20
  • QGIS executes all python plugins from this folder, not only the core plugins: https://i.stack.imgur.com/BeX1r.png . I have tested this before with several plugins. That's why I wrote: "Plugins located in the apps folder (e.g. C:\OSGeo4W64\apps\qgis-ltr\python) are working". – Thomas B Sep 26 '18 at 06:54
  • I also tried this, but i must admit, it was not a full functioning plugin. My idea was to use a plugin as a startup script. I tried to use initGui() as an entry point, because that's where the button or menu entries are added to qgis. Unfortunately even __init__.py wasn't executed. This and the explicit mention that the core plugins are seleted by the developer team leads to my conclusion. Therefor using a plugin as a startup may be investigated further. – Andreas Müller Sep 26 '18 at 07:53
  • I also considered using a plugin as a startup but realised that it is not an option as it can be deactivated. I want to check if a ntv2-grid is correctly integrated in QGIS during startup. If the plugin would be deactivated this could lead to inaccurate data, so a solution that could be deactivated by the user is a showstopper – Thomas B Sep 26 '18 at 09:05