[Qgis-user] How to set python search path for standalone script?

Jürgen E. Fischer jef at norbit.de
Wed May 4 04:49:25 PDT 2016


Hi David,

On Wed, 04. May 2016 at 11:43:24 +0000, David Shi wrote:
> How to set python search path for standalone script?
> 
> I am writing a standalone script, but it can not import qgis.core and other processing.   modules.

In OSGeo4W there is a batch file python-qgis.bat you can pass your script to:

@echo off
call "%~dp0\o4w_env.bat"
@echo off
path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/qgis
set GDAL_FILENAME_IS_UTF8=YES
rem Set VSI cache to be used as buffer, see #6448
set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt4\plugins
set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python;%PYTHONPATH%
"%OSGEO4W_ROOT%"\bin\python.exe %*

PYTHONPATH and QGIS_PREFIX_PATH are most important.


Jürgen

-- 
Jürgen E. Fischer           norBIT GmbH             Tel. +49-4931-918175-31
Dipl.-Inf. (FH)             Rheinstraße 13          Fax. +49-4931-918175-50
Software Engineer           D-26506 Norden             http://www.norbit.de
QGIS release manager (PSC)  Germany                    IRC: jef on FreeNode                         
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20160504/99df4072/attachment.sig>


More information about the Qgis-user mailing list