For a long time I wanted to give a go at creating a QGIS plugin. Nothing in particular, just a ‘Hello World’ plugin or similar so I could understand how the whole QGIS/python thing hangs together. Seasoned readers of my blog may have noticed by now that I mainly (only?) work on Windows OS. And let me tell you, trying to find exactly what is needed in terms of python libraries for being able to create a simple form in QGIS proved to be a big challenge. .
But I have figured it out and those are my notes in case you also want to give it a try. They don’t go as far as creating a plugin. They merely create a custom form you can use for editing a layer. But I consider this a HUGE step for me nevertheless!
I was running QGIS 1.8 on a Windows 7 64-bit laptop. I also had ArcGIS 10 installed and for Python development I use PyScripter. This posed an interesting problem of how to use PyScripter for both ArcGIS and QGIS but I had solved this earlier
So next, I apparently had to use PyQt4 for being able to create forms within QGIS. But DO NOT use the version for Python 2.7 from this link as -as I found out at my expense- its not compatible with QGIS. The safest way is to use the OSGeo4W Installer. Select the Advanced install and select to download and install the packages as shown in the next screenshot. Not entirely sure that ALL these are required but they work for me so….
Note the last item on the list (SIP) which the version I have is the previous from the current one. I *think* you need this version otherwise you get runtime errors when trying to load the PyQt4 libraries i.e. “RuntimeError: the sip module implements API vXX to vXX but the PyQt4.QtCore module requires API vXX”
Yes- it was a very trial and error job…
Moving on, you can then open PyScripter for Python 2.7 and check if you can load the PyQt4 libraries by running on the python prompt:
>>> from PyQt4.QtCore import * >>> from PyQt4.QtGui import *
If all goes well you should not get any errors. To be on the safe side and ensure you have the same setup in the QGIS python environment (it may sound an unecessary step but trust me, its not) run the above command on the QGIS python window as well.
And so, finally, you are ready to make your custom form. But for this I simply followed Nathan’s example from his QGIS blog
Next step would be to create my Hello World plugin. On a next post….