[GIS] ImportError: no module named site

pyqgispythonqgiswindows

I am developing a standalone app using qgis librarys and run the python inside qgis. I import the librarys with no errors but I have one last error: ImportError: no module named site. I define the paths like this:

 'PYTHONHOME': 'C:\OSGeo4W64\apps\Python27',
 'PYTHONPATH': 'C:\OSGeo4W64\apps\Python27\Lib',
 'PATH': 'C:\OSGeo4W64\apps\qgis\bin;C:\OSGeo4W64\bin;C:\OSGeo4W64\apps\Python27'

I see that site.py is in 'C:\OSGeo4W64\apps\Python27\Lib', so I still have the error. The app doesn't read the correct site.py?

Best Answer

Try this:

SET OSGEO4W_ROOT=C:\OSGeo4W
SET QGISNAME=qgis
SET QGIS=%OSGEO4W_ROOT%\apps\%QGISNAME%
set QGIS_PREFIX_PATH=%QGIS%

CALL %OSGEO4W_ROOT%\bin\o4w_env.bat

: Python Setup
set PATH=%OSGEO4W_ROOT%\bin;%QGIS%\bin;%PATH%
SET PYTHONHOME=%OSGEO4W_ROOT%\apps\Python27
set PYTHONPATH=%QGIS%\python