I am trying to set QGIS 2.8.1 (Linux Mint 17.2) to add the filename/path to layouts.

I am using this post as a guide How to add the current project path in Print Composer? However, I haven't got startup.py - I ran searchmonkey on my entire hard disk. The PyQGIS cookbook says "...if it's exists" but no reference to how to create it.

I tried creating a file of that name & pasting the code into it but QGIS wouldn't start, with Python-related complaints. I'm assuming the file should have a header & instructions, like an HTML document does? I can't seem to find this. I've looked in the QGIS settings to try & find it, with no success. BTW, I'm completely new to Python.

  • You might need to add the contents of what you put into your startup.py file. This file is just a Python script, so it may not need a 'header' or instructions like an HTML document. Your Python-related complaints would also help. – Richard Morgan Apr 5 '16 at 13:40
  • I paste this into a newly-created startup.py placed in /home/jonathan/.qgis2/python: from qgis.core import QgsProject @qgsfunction(0, "Python") def projectpath(values, feature, parent): return QgsProject.instance.fileName() – user3418765 Apr 5 '16 at 14:30
  • Couldn't load qgis.user. Python support will be disabled. Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/dist-packages/qgis/utils.py", line 478, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/usr/lib/python2.7/dist-packages/qgis/user.py", line 30, in execfile(startuppy, locals(), globals()) File "/home/jonathan/.qgis2//python/startup.py", line 3, in @qgsfunction(0, "Python") NameError: name 'qgsfunction' is not defined Python version: 2.7.6 (default, Jun 22 2015, 18:01:27) [GCC 4.8.2] – user3418765 Apr 5 '16 at 14:30
  • its not finding the qgsfunction decorator. try adding from qgis.utils import qgsfunction (see this blog post by NathanW) – Steven Kay Apr 5 '16 at 14:55
  • Starts up OK now. Just need to digest that post of Nathan's - I had looked at it, but somewhat blankly. Need to get my head round Python a bit. – user3418765 Apr 5 '16 at 15:24

Browse other questions tagged or ask your own question.