I was wondering if it's possible to use Python and QGIS out of QGIS environment (namely, avoiding the use of the console). I'm pretty new to QGIS, I've been always using ArcGIS 10.1. What I am looking for is a thing similar to that "arcpy" module, since I work with tons of data at a time. Moreover, I'd like to use a good IDE, any suggestion? I'm using qgis 1.8, python 2.7.2 32bit, windows 7 64bit. P.S.: I couldn't really come up with a solution, neither following the instructions found in http://www.qgis.org/pyqgis-cookbook/intro.html#python-applications. Hope someone will enlight me!

  • What error did you get when following the cookbook?
    – Nathan W
    Jan 8 '13 at 22:03

Under the hood QGIS uses GDAL/OGR for most of the functions. So, the Python API for GDAL would be the closest analogy to using ArcPY in a stand-alone situation.

You can use the installation that comes with QGIS or have a separate installation of Python and GDAL. Other addons that complete the 'package' I would include

The last two are particularly relevant for raster processing. Have a look here for a tutorial on stand-alone geoprocessing using GDAL. This will get you going.

  • Thank you so much, this is really helpful, think I'm going through all the documentations t learn more about how everything works! It's a bit old though, but it's superfine!
    – umbe1987
    Jan 9 '13 at 9:45

Yes building a standalone application out of QGIS using Python and the QGIS libraries is possible.

I have some small, but hopefully growing, example set at https://github.com/NathanW2/pyqgis-playground

The main thing is having the path the libraries setup correctly. When I'm on windows I use something like this:

set PYTHONPATH=C:\OSGeo4W\apps\qgis-dev\python
Set PATH=C:\OSGeo4W\apps\qgis-dev\bin;%PATH%
set QGISHOME=C:\OSGeo4W\apps\qgis-dev\

python yourfile.py

and I run it from within inside the OSGeo4W shell. You can test you have everything setup correctly by running the above set commands inside a OSGeo4W shell and then doing:

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>>>> import qgis.core

If it works you should get no errors.

  • I've been trying hard to set the system environment to point to the correct folders like you suggest, but still having troubles. When I try to import the "qgis.core" module, the SHELL tells me a DLL (which I suppose to be "qgis_core.dll") couldn't be load. I'm using a SHELL found in the installation of Python27. Guess if the ArcGIS references in the system environment might conflict with the QGIS ones...
    – umbe1987
    Jan 9 '13 at 9:55
  • Try using the Python that comes with OSGeo4W it has everything setup
    – Nathan W
    Jan 9 '13 at 10:05
  • Ehy Nathan I came up with your page googling in the web (woostuff.wordpress.com/2011/09/27/…), really interesting!
    – umbe1987
    Jan 9 '13 at 10:21
  • Howerver, could you please tell me what is the SHELL that comes with the installation of QGIS. I didn't use the OSGeo4W setup, but one that I found in the QGIS official website, so it might have installed different files than those you could have. I'd really like to solve the problem of the system environment setting, maybe if you want, you could have a look
    – umbe1987
    Jan 9 '13 at 10:24
  • at my other question... gis.stackexchange.com/questions/45473/…
    – umbe1987
    Jan 9 '13 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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