5

In QGIS 3 on Win10 we use a startup.py script for setting up e.g. database connections and a couple of other things, residing in C:\Users\me\AppData\Roaming\QGIS\QGIS3

What we are after is to centrally deploy the startup.py without having to distribute it to each of our clients at every script change.

First try was to make use of the PYQGIS_STARTUP environment variable, but this fails, because startup.py makes use of qgis.* modules which are of course not available before QGIS initialization is complete.

How can we centrally deploy our startup.py in order to apply changes on every client without having to distribute it?

2 Answers 2

11

Our solution is to let the environment variable PYQGIS_STARTUP point to a very simple pre-startup.py script that copies the startup.py from a central location to the required users QGIS 3 directory:

import os, shutil

account = os.getlogin()
shutil.copy2('X:/central/location/for/startup.py', 'C:/Users/{0}/AppData/Roaming/QGIS/QGIS3'.format(account))

QGIS 3 then executes this previously copied startup.py.

0
3

An alternative to startup.py, which is local, is the use of the init_scripts folder.

By default the init_scripts is set to QgsApplication.pkgDataPath() + '/init_scripts'.

All .py files inside that folder will run on qgis launching by alphabetic order.

You can use the QGIS_INIT_SCRIPTS_DIRECTORY environment variable to point to another folder, including a path in a shared folder.

1
  • are you sure that this is already implemented in QGIS? I think it was only implemented in the boundlessgeo QGIS fork. I can't find QGIS_INIT_SCRIPTS_DIRECTORY or init_scripts in the current codebase of QGIS. It would be nice if this functionality would be merged into the QGIS repository. Jan 5 at 7:05

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.