[GIS] “ImportError: no module named qgis.core” in standalone app

installationpyqgis

I am developing a standalone app (in Windows) using libraries from QGIS. When I run the script in cmd, I get the ImportError: no module named qgis.core. I read in several posts that I need to configure the PYTHONPATH and PATH but I also read that with OSGEO4W installation there is no need to configure.

How do I do that?

I am very confused and I try several ways but without success. Now I am reinstalling QGIS thorugh OSGEO4W.

So, I need to import QGIS libraries in a script outside QGIS. This script runs inside Python27 folder that I have already installed for other app.

Is it possible to use the QGIS libraries through this directory?

If not what is the solution?


I resolved the import qgis.core error, just following the instructions of how to import qgis modules outside qgis. Now the error is different: ImportError: DLL load failed: %1 is not a valid Win32 application. And the error is related with import sip. I search and find that I use python from OSGEO4W (64bits) and external python (32 bits).

How I can solve it?

Best Answer

I'm not sure if it helps for you but in principle you set paths either by writing the commands into the DOS-box (started with cmd) or by setting them via a batch file. To use eclipse with QGIS the following lines have been recommended. All you have to do is to write them into a plain text file and give its filename a .bat ending.

Just make sure to replace by your own file names. Instead of eclipse.exe (last line) use your standalone app:

call "C:\Program Files (x86)\QGIS Wien\bin\o4w_env.bat"  
set PATH=%PATH%;C:\Program Files (x86)\QGIS Wien\apps\qgis\bin;C:\Program Files (x86)\QGIS Wien\bin  
SET PYTHONHOME=C:\Program Files (x86)\QGIS Wien\apps\Python27  
Set PYTHONPATH=C:\Program Files (x86)\QGIS Wien\apps\qgis\python  
eclipse.exe