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


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.


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.

  • 3
    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.
    – Thomas B
    Commented Jan 5, 2022 at 7:05
  • 2
    Yes, I presume that this feature is not available for a "regular" QGIS version. I create "Feature request": github.com/qgis/QGIS/issues/55714
    – posiki
    Commented Dec 27, 2023 at 13:12
  • 1
    It seems to me this answer doesn't apply to the official QGIS distribution. Commented Dec 28, 2023 at 7:04

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.