5

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 Desktop 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.

How do I do this?

I'm thinking of settings environment variables etc.

I am new to both QGIS and Python.

7

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:

@ECHO OFF
set OSGEO4W_ROOT=C:\OSGeo4W
set PATH=%OSGEO4W_ROOT%\bin;%OSGEO4W_ROOT%\apps\qgis-dev\bin;%PATH%
SET PYTHONHOME=%OSGEO4W_ROOT%\apps\Python27
set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis-dev\python
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis-dev\
  • 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
  • 2
    ArcGIS ships with it's own version of Python mine lives in C:\Python27\ArcGIS10.1\python.exe. You can't really have them both setup at the same time else you get conflicts. – Nathan W May 29 '13 at 21:08
0

I just posted Using PyQGIS, ArcPy, NumPy, SciPy Together in Windows Command Prompt to this that may be helpful. This is my take on how to utilize multiple python installations on the same computer.

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.