- Announcing the release of QGIS 1.5 'Tethys'
- Quantum GIS on steroids
- Annotation tools
- Announcing the release of QGIS 1.4.0 'Enceladus'
- Carson Farmer's report back on the Vienna Hackfest
- Vienna Hackfest 2009 Report Back
- Introducing the QGIS Hackfest (Vienna 2009) crew
- Announcing the release of QGIS 1.3.0 'Mimas'
- Announcing the releases of QGIS 1.0.2 (stable) and QGIS 1.1.0 'Pan' (unstable).
- Summer of Code project: Label placement
QGIS tutorials in Python
Some time ago I've started with porting Tim's tutorials posted in the blog to Python. The main reason
of doing it was to check that bindings work correctly. I thought that some people might be interested in using them so you can download them.
Download the tutorials:
- current version: 1.0 or later
- old version: 0.9.2 - 0.11
- old version: 0.9.0 or 0.9.1
UPDATE (Mar 16, 2009): Updated to QGIS 1.0 API
UPDATE (Jan 24, 2008): Updated with API changes which will become QGIS 0.9.2
UPDATE (May 5, 2007): Fixed tutorial 6 which was broken due API changes in vector providers.
Instructions
- unpack archive
- for every tutorial in mainwindow.py set 'qgis_path' variable to your qgis installation prefix
(needed for loading providers, projections database etc.) - set environment variables:
Linux: (when /home/wonder/qgis is used)
export LD_LIBRARY_PATH=/home/wonder/qgis/lib export PYTHONPATH=/home/wonder/qgis/share/qgis/python
Windows (when c:\qgis is used)
set PATH=c:\qgis;%PATH% set PYTHONPATH=c:\qgis\python
PYTHONPATH is there to tell python where to search for QGIS Python bindings, LD_LIBRARY_PATH (resp. PATH)
tells system where to look for QGIS libraries that Python bindings need to work. - run examples: python mainwindow.py
For running the tutorials you need QGIS from recent SVN trunk (>= r6833).
Remember that when you modify the UI or resource files, you must run 'make' to recreate files generated by pyuic4 and pyrcc4.
Copyright plugin in Python
For testing purposes I've ported also plugin for displaying copyright text from C++ to Python.
This can be helpful in case you plan to develop a Python plugin and would like to have a simple
example. It doesn't have any new functionality in comparison to original plugin. Download it here.
To run it just unpack the archive and copy the unpacked directory to python plugins dir - that's (qgis_prefix)/share/qgis/python/plugins on Linux/Mac or (qgis_prefix)/python/plugins on Windows. You might need to create 'plugins' directory if it doesn't exist yet. More information about python plugins is on wiki.
- Martin Dobias's blog
- Login or register to post comments
- 24263 reads

Your tutorials on os x
hi, I am trying to use your 2_basic_main_window tutorial but can't get it running properly.
I have had various error messages but the latest is as follows
No valid projection. Unable to set map units.
No valid projection. Unable to set map units.
No valid projection. Unable to set map units.
No valid projection. Unable to set map units.
I have set
export LD_LIBRARY_PATH=/Applications/qgis0.11.0.app/Contents/MacOS/lib
export PYTHONPATH=/Applications/qgis0.11.0.app/Contents/MacOS/share/qgis/python
export QGISHOME=/Applications/qgis0.11.0.app/Contents
running 0.11.0 os os 10.5.5
Thanks,
Ian
Help needed on building a customized QGIS application
Hi Martin and Tim,
Thank you very much for writing such a wonderful script.
But when i tried to run it, it is giving the import error while importing qgis.core and other libraries.
I tried to put the qgis folder inside the python folder and also by setting the path variable.
but i cannot run it.
I know i am doing something wrong in between. But unable to detect it.
it will be very kind of you if you can help me out.
Thanks in advance.
Bishwarup
Editing Tool Bars
Thank you for this valuable tutorials.
I'would Like to add a tool bar button for digitizing a polygon.
I tried to use QgsMaptoolAddRing, but unfortunately it's fail.
How could we implement this feature?
Thanks a lot
PYTHONPATH and LD_LIBRARY_PATH under mac os x
Sorry,
but under Mac OS X (with qgis from svn) I recive this error:
Traceback (most recent call last):
File "/tutorials/2_basic_main_window/mainwindow.py", line 13, in
from qgis.core import *
ImportError: No module named qgis.core
So, under Mac OS X, how I must to set LD_LIBRARY_PATH and PYTHONPATH and where I can found qgis.core and qgis.gui?
Thanks a lot
Interface Control Systems
Please let me know if I should be targeting a demonstration tutorial or a final usable plugin to handle 3d interface control of systems by piping 3d relative positions of a ball in a camera feed. Obviously this is intended to couple to the menu and data manipulation systems, but the debate is the use of python versus other options for this purpose. Someone else´s tut txt is available at http://remedials.org/BalliesScript.txt and covers quite well the background of this method of interface.
-Wilfred
WilfredGuerin@gmail.com
tutorial 2_basic_main_window
I have finally got python 2.5 bindings created for qgis and I'm keen to get started so thought I'd begin with your tutorial. However, I get this error when running mainmenu.py:
No Data Providers:
No Data Provider Plugins
/home/wonder/qgis/inst/plugins
No vector layers can be loaded. Check your QGIS installation
Can't open database: unable to open database file
Error:
Could not open SRS database /home/wonder/qgis/inst/resources/srs.dbError(14)
: unable to open database file
Have I missed something?
Problem in the importing qgis.core, qgis.gui modules
Hi Martin and Tim,
Thank you very much for writing such a wonderful script.
But when i tried to run it, it is giving the import error while importing qgis.core and other libraries.
I tried to put the qgis folder inside the python folder and also by setting the path variable.
but i cannot run it.
I know i am doing something wrong in between. But unable to detect it.
it will be very kind of you if you can help me out.
Thanks in advance.
Bishwarup
Path
You must set the path to your QGIS installation, open mainwindow.py and change qgix_prefix variable appropriately.
set Path under Ubuntu
Hello,
for those using Ubuntu Linux:
I found out that the tutorials work when using
qgix_prefix = "/usr"