Skip to main content
1 of 3
Germán Carrillo
  • 37k
  • 5
  • 125
  • 180

You're only missing one line in your script to make it work properly. Namely, you need to set the prefix path for allowing QGIS to initialize data providers. So, right before the qgis.initQgis(), add this line:

qgis.setPrefixPath( qgis_prefix, True )

where qgis_prefix on my Windows machine is "C:/OSGeo4W64/apps/qgis/". See this answer for tips on how to know what is your QGIS prefix path.

Once you do that, run your script and you won't obtain the 0 layers loaded message anymore using your project. With no prefix path, QGIS cannot create valid layers from your project, so they apparently aren't loaded.

Germán Carrillo
  • 37k
  • 5
  • 125
  • 180