Question

As my previous question has been closed, I'm trying to improve it to let the community understand it could be usefull for a broad number of users. I found a SHELL LAUNCHER that permit to bypass the system environment setting in the "traditional way" to integrate python and QGIS (namely using PyQGIS). The original one works perfectly (find it at http://inasafe.linfiniti.com/html/id/developer-docs/platform_windows.html). I've been trying to modify it to let anybody use his own favourite IDE (and not the windows command prompt as the original one is supposed to do). Therefore, I made my modifications and come eventually to this comand launcher:

@echo off
SET OSGEO4W_ROOT=C:\QUANTU~1
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\apps\Python27\Lib\idlelib\idle.pyw # this is the IDE I wanna use, but You can freely point to whatever You'd like
@echo off
SET GDAL_DRIVER_PATH=%IDLE%\bin\gdalplugins\1.9
path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass-6.4.2\lib
path %PATH%;"%OSGEO4W_ROOT%\apps\Python27\Scripts\"

set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python;
set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\Python27\Lib\site-packages
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis

start "Quantum GIS Shell" /B "cmd.exe" %*

Anyway, when I run it, it opens idle.pyw but I can't import the modules like if the system variables are still not set properly, although it seems they are by investigating the sys.path. The error I get when I import (for instance) "qgis.core" module is:

ImportError: DLL load failed: Impossibile trovare il modulo specificato # (impossible to import the specified module)

My OS is Windows XP sp3, Python is 2.7.3 and QGIS is Lisboa v.1.8. I hope someone could help me and that this could contribute to hsolve the common problem that is importing PyQGIS modules.

Was it helpful?

Solution

Eventually I managed to have the personal shell launcher! The trick was to investigate the o4w_env.bat file in order to understand what the "call" at the second line actually does.

So I tried and succeeded with this:

  1. Copy the idle.pyw (or the IDE you'd like to use to the Quantum GIS main folder (in my case it was C:/Quantum_GIS_Lisboa)

  2. Copy the SHELL LAUNCHER (see point 3) with extension .bat in "\bin"

  3. Run this SHELL LAUNCHER (simple double click):

    @echo off
    
    SET OSGEO4W_ROOT=C:\QUANTU~1
    
    call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
    
    @echo off
    
    SET GDAL_DRIVER_PATH=%IDLE%\bin\gdalplugins\1.9
    path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
    path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass-6.4.2\lib
    path %PATH%;"%OSGEO4W_ROOT%\apps\Python27\Scripts\"
    
    set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python;
    set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\Python27\Lib\site-packages
    set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis
    
    start "Quantum GIS Shell" /B "idle.pyw" %* # This is where you specify the IDE 
    # you want to use, mine is "idle.pyw", but if You copy another one (as in point 1), 
    # you should replace "idle.pyw" with "<YOUR_IDE>"
    

Hope this could help anybody. Cheers!

OTHER TIPS

Run Qgis and open python console type the following

  1. import sys
  2. sys.path

    Now copy this path and include the sys path at the top for your python code.

Now run that code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top