1

We use QGIS in the company on many PCs. For one, many settings are now to be regulated via the startup.py. I am looking for a way that the startup.py no longer has to be stored under the personal folder of the user, i.e. under: C:\Users\AppData\Roaming\QGIS\QGIS3

I want that the file can be located on a central network drive and QGIS looks for the startup.py at this location. I want to set this setting in qgis_global_settings.ini and have tried the following code for this.

I use the qgis version 3.22.16 LTR.

[PythonPlugins]
#Path to the Startup.py
PythonPlugins\startup\file=P:\QGIS\8_Update_QGIS\QGIS_Update\QGIS_Config\startup.py

Unfortunately, it does not work.

2
  • you can start qgis from the commandline or from a batchfile with the option: --code path/to/scriptname.py
    – eurojam
    Jul 12 at 7:14
  • i would like to control it via qgis_global_settings.ini, so that the user has to consider as little as possible. During the installation the qgis_global_settings.ini should be placed once in the installation directory and then further settings should be controlled via the central startup.py. A further batch file would make the installation process more difficult.
    – joe_gerner
    Jul 12 at 7:21

1 Answer 1

0

The key is to use a PYQGIS_STARTUP environment variable pointing to the path of your custom QGIS Python script. It doesn't have to be called startup.py, it can be called anything_you_want.py.

If you're using a QGIS_GLOBAL_SETTINGS_FILE system environment variable to tell QGIS to load a custom qgis_global_settings.ini from a network drive, you can also set a PYQGIS_STARTUP system environment variable.

If you're creating a custom qgis_global_settings.ini and storing it in the installation folder on each device that you install QGIS on, then you can set the PYQGIS_STARTUP environment variable in the .ini file (in the [qgis] section).

[qgis]
customEnvVars="overwrite|PYQGIS_STARTUP=/path/to/custom_startup.py"

However, if you're using the custom startup.py script to control settings normally configured in qgis_global_settings.ini why not just set them in qgis_global_settings.ini and store that on your network drive? If you're providing custom pyqgis functions in the startup.py, you can then keep settings separate from code.

4
  • Unfortunately it doesn't quite work for me. I have the startup.py on the following network drive: P/QGIS/8_Update_QGIS/QGIS_Update/QGIS_Config/startup.py and for this I have added the following code to qgis_global_settings.ini: [qgis] customEnvVars="overwrite|PYQGIS_STARTUP=P:/QGIS/8_Update_QGIS/QGIS_Update/QGIS_Config/startup.py
    – joe_gerner
    Jul 18 at 8:08
  • Define "doesn't quite work"? Nothing happens, you get an error, or something else? It works for me with a simple script that logs a message using QgsMessageLog.logMessage(etc...) stored on a Windows network drive. Perhaps check your path.
    – user2856
    Jul 18 at 9:08
  • Nothing happens, so the file is not called when starting qgis
    – joe_gerner
    Jul 18 at 9:25
  • I can't reproduce. It works for me with any .py script stored locally or on a network drive, either set by a PYQGIS_STARTUP=some script.py environment var or via customEnvVars="overwrite|PYQGIS_STARTUP=some script.py" in a .ini file. Perhaps check your .ini file is getting loaded.
    – user2856
    Jul 18 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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