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'm trying to create a standalone qgis app using pyqgis, i'll be deploying it by copying the install folder of qgis and source folder of my app, and so for the testing purposes i copied qgis install folder (1.8.0) to some other computer without qgis installation to begin with; then i tried to test the qgis.gui and qgis.core imports, but no matter what PYTHONPATH (or PATH) i set, i keep getting ImportError "no module named ...".

What's wird is, if i modify qgis.bat to this new location and run it, Qgis opens without a problem and all imports work through console inside qgis. Then i simply duplicated qgis.bat and removed the last line which runs qgis then added the line which runs my application instead. For some reasons, imports are still unavailable, so im wondering where are actual python binding files for qgis_gui.dll and qgis_core.dll because i cant find them anywhere inside qgis install dir.

My .bat looks like this:

@echo off
SET OSGEO4W_ROOT=c:\IMS\Qgis
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\apps\grass\grass-6.4.2\etc\env.bat
@echo on
PATH %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin;%OSGEO4W_ROOT%\apps\grass\grass-6.4.2\lib;%OSGEO4W_ROOT%\apps\qgis\python\qgis;
SET PYTHONPATH = c:\IMS\QGis\apps\qgis\bin\
python c:\IMS\IMS\ims.py
share|improve this question

2 Answers 2

up vote 3 down vote accepted

This is the correct path setup:

@echo off
SET OSGEO4W_ROOT=c:\IMS\Qgis
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\apps\grass\grass-6.4.2\etc\env.bat

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

qgis.core and qgis.gui are located in the qgis\python\qgis folder but you only set PYTHONPATH to the qgis\python folder because qgis is a package.

share|improve this answer
    
Thanx, i ll test when i get home today ;) –  U2ros Mar 12 '13 at 15:11
    
Thanks, works perfectly, after i modified your snippet to my locations. Again, thanks –  U2ros Mar 14 '13 at 19:24

In the web only your solution works!!!! ;)

On Windows 7 & QGIS standalone (no installer OSGeo4W) my .bat is:

SET OSGEO4W_ROOT=C:\PROGRA~1\QUANTU~1

set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python;%PYTHONPATH%
Set PATH=%OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
set QGISHOME=%OSGEO4W_ROOT%\apps\qgis
echo off
call %OSGEO4W_ROOT%\bin\o4w_env.bat
call %OSGEO4W_ROOT%\apps\grass\grass-6.4.2\etc\env.bat
echo off

start "My Quantum GIS App" /B %OSGEO4W_ROOT%\bin\python.exe X:\test.py
share|improve this answer

Your Answer

 
discard

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.