Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have both ArcGIS 10.1 and QGIS 1.8 installed and both include Python 2.7 in slightly different setups and in different folders (c:\Python27\ArcGIS10.1\ and c:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27).

It is only ArcGIS which include python.exe, while it is really QGIS I would like to start experimenting with for some scripting, but preferably just running my scripts from the command console.

Are there any recommendations on how to do this smartest? I'm thinking of settings environment variables etc.

I am new on both QGIS and python.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

While you can do it with the standalone installed copy of QGIS I would highly recommend installing QGIS and QGIS-dev using the OSGeo4W installer. OSGeo is easier to update and lets you get the latest stuff.

That will install Python into C:\OSGeo4W\app\Python27 and let you run Python from the OSGeo4W shell. python.exe lives in C:\OSGeo4W\bin.

I have some examples of QGIS stuff at https://github.com/NathanW2/pyqgis-playground

Use the following batch file as a bootstrap to your python file:

set PATH=%OSGEO4W_ROOT%\bin;%OSGEO4W_ROOT%\apps\qgis-dev\bin;%PATH%
set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis-dev\python
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis-dev\
share|improve this answer
I have installed OSGeo4W instead of QGIS alone and have created this batch files: SET OSGEO4W_ROOT=C:\OSGeo4W SET PYTHONHOME=%OSGEO4W_ROOT%\apps\Python27 Set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python;%PYTHONPATH% Set PATH=%OSGEO4W_ROOT%\apps\qgis\bin;%PATH% Set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis\ %OSGEO4W_ROOT%\bin\python test.py The test test.py file only includes one line:</br>from qgis.core import *</br>But it fails with the error message that the DLL could not be loaded. Not saying which DLL it is. –  Uffe Kousgaard May 24 '13 at 12:12
Adding line breaks failed completely... –  Uffe Kousgaard May 24 '13 at 12:18
@UffeKousgaard see update –  Nathan W May 24 '13 at 12:47
OK, thanks, I have gotten as far as opening a SHP file now. Just wondering, why all I get from this code is a "feature ID 0": qgis.org/pyqgis-cookbook/vector.html. no Error messages. –  Uffe Kousgaard May 24 '13 at 13:57
That needs to be updated for the new version. Try this: gist.github.com/NathanW2/5525338 –  Nathan W May 24 '13 at 21:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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