<div dir="ltr">Try setting QGIS_PREFIX_PATH=/usr<div><br><div style>Then make sure the path to the QGIS libs is either configured in ld.so.conf.d/ or LD_LIBRARY_PATH</div><div style><br></div><div style>In my case, I have QGIS installed in /home/gsherman/qgis_master and this sequence works:</div>
<div style><br></div><div style>From the shell:</div><div style>export LD_LIBRARY_PATH=/home/gsherman/qgis_master/lib<br></div><div style>export QGIS_PREFIX_PATH=/home/gsherman/qgis_master<br></div><div style>export PYTHONPATH=/home/gsherman/qgis_master/share/qgis/python<br>
</div><div style><br></div><div style>In Python:</div><div style><br></div><div style>app = QgsApplication(['/home/gsherman/qgis_master'], False)<br></div><div style>app.initQgis()<br></div><div style><div>for provider in QgsProviderRegistry.instance().providerList():</div>
<div>    print provider</div><div>   ...:     </div><div>WFS</div><div>delimitedtext</div><div>gdal</div><div>gpx</div><div>memory</div><div>mssql</div><div>ogr</div><div>osm</div><div>ows</div><div>postgres</div><div>spatialite</div>
<div>sqlanywhere</div><div>wcs</div><div>wms</div></div><div style><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Feb 25, 2013 at 12:45 AM, Nils Olaf de Reus <span dir="ltr"><<a href="mailto:nils.de.reus@gmail.com" target="_blank">nils.de.reus@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi everyone,<br>
<br>
When trying to use the qgis libraries from an external script (that<br>
is, a script running not within the context of the embedded console of<br>
QGIS), I get only a severely limited selection of available data<br>
providers. A number of libraries that load fine from inside the<br>
context of QGIS' embedded python console, fail to load when initQgis<br>
is used from a standalone external script.<br>
<br>
I have a Linux 2.6.32-5-amd64 x86_64 GNU/Linux platform, running<br>
Debian Squeeze and the 1.8 release of QGIS for Squeeze from the<br>
official repository at <a href="http://qgis.org/debian" target="_blank">http://qgis.org/debian</a>. To test if the problem<br>
described below still existed with a newer version of QGIS, I created<br>
a clean Debian Squeeze chroot environment, and installed the latest<br>
nightly build. The problem still existed with the nightly, same as in<br>
the 1.8 release.<br>
<br>
<br>
The provider lib files are present in the usual plugin directory:<br>
<br>
nils@fennek:~$ ls /usr/lib/qgis/plugins<br>
libcoordinatecaptureplugin.so  libmemoryprovider.so<br>
libdelimitedtextplugin.so      libmssqlprovider.so<br>
libdelimitedtextprovider.so    libofflineeditingplugin.so<br>
libdiagramoverlay.so           libogrprovider.so<br>
libdxf2shpconverterplugin.so   liboracleplugin.so<br>
libevis.so                     libosmprovider.so<br>
libgdalprovider.so             libpostgresprovider.so<br>
libgeorefplugin.so             librasterterrainplugin.so<br>
libgpsimporterplugin.so        libroadgraphplugin.so<br>
libgpxprovider.so              libspatialiteprovider.so<br>
libgrassplugin.so              libspatialqueryplugin.so<br>
libgrassprovider.so            libspitplugin.so<br>
libgrassrasterprovider.so      libwfsprovider.so<br>
libheatmapplugin.so            libwmsprovider.so<br>
libinterpolationplugin.so      libzonalstatisticsplugin.so<br>
<br>
<br>
My external script goes through the usual steps, shown below in an<br>
interactive session for easy replication:<br>
<br>
nils@fennek:~$ python<br>
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)<br>
[GCC 4.4.5] on linux2<br>
Type "help", "copyright", "credits" or "license" for more information.<br>
>>> from qgis.core import *<br>
>>> app = QgsApplication([u'/usr'], False)<br>
>>> print app.showSettings()<br>
Application state:<br>
Prefix:         /usr<br>
Plugin Path:            /usr/lib/qgis/plugins<br>
Package Data Path:      /usr/share/qgis<br>
Active Theme Name:<br>
Active Theme Path:      :/images/themes//<br>
Default Theme Path:     :/images/themes/default/<br>
SVG Search Paths:       /usr/share/qgis/svg/<br>
                /home/nils/.qgis//svg/<br>
User DB Path:   /usr/share/qgis/resources/qgis.db<br>
<br>
>>> app.initQgis()<br>
<br>
Now if I check which providers are there, I only get three..<br>
<br>
>>> for provider in QgsProviderRegistry.instance().providerList():<br>
...     print provider<br>
...<br>
delimitedtext<br>
gdal<br>
gpx<br>
<br>
<br>
..while that exact same statement inside Qgis' embedded Python Console<br>
yields all thirteen providers:<br>
<br>
>>> for provider in QgsProviderRegistry.instance().providerList():<br>
...     print provider<br>
...<br>
WFS<br>
delimitedtext<br>
gdal<br>
gpx<br>
grass<br>
grassraster<br>
memory<br>
mssql<br>
ogr<br>
osm<br>
postgres<br>
spatialite<br>
wms<br>
<br>
<br>
Sofar, I've traced it to the point where during initQgis(), the<br>
creation of the QgsProviderRegistry will reject those libraries that<br>
return False on the test if QLibrary's load() method will succesfully<br>
load them. This too can be shown from the interactive python console.<br>
First in the external console:<br>
<br>
>>> from PyQt4 import QtCore<br>
>>> QtCore.QLibrary(u'/usr/lib/qgis/plugins/libdelimitedtextprovider.so').load()<br>
True<br>
>>> QtCore.QLibrary(u'/usr/lib/qgis/plugins/libgdalprovider.so').load()<br>
True<br>
>>> QtCore.QLibrary(u'/usr/lib/qgis/plugins/libgpxprovider.so').load()<br>
True<br>
>>> QtCore.QLibrary(u'/usr/lib/qgis/plugins/libogrprovider.so').load()<br>
False<br>
>>> QtCore.QLibrary(u'/usr/lib/qgis/plugins/libspatialiteprovider.so').load()<br>
False<br>
>>><br>
<br>
..well, I think you see the pattern. Outside of those three<br>
('delimitedtext', 'gpx' and 'gdal'), QLibrary doesn't seem able to<br>
load any of the other provider libraries.<br>
<br>
Now my first guess when QLibrary can't load a library would be that<br>
something is wrong with that library. Except of course that when these<br>
same commands are issued inside the embedded console under Qgis, these<br>
same libs load fine:<br>
<br>
>>> from PyQt4 import QtCore<br>
>>> QtCore.QLibrary(u'/usr/lib/qgis/plugins/libdelimitedtextprovider.so').load()<br>
True<br>
>>> QtCore.QLibrary(u'/usr/lib/qgis/plugins/libgdalprovider.so').load()<br>
True<br>
>>> QtCore.QLibrary(u'/usr/lib/qgis/plugins/libgpxprovider.so').load()<br>
True<br>
>>> QtCore.QLibrary(u'/usr/lib/qgis/plugins/libogrprovider.so').load()<br>
True<br>
>>> QtCore.QLibrary(u'/usr/lib/qgis/plugins/libspatialiteprovider.so').load()<br>
True<br>
>>><br>
<br>
<br>
I've tried making my sys.path identical between the embedded and<br>
external python sessions. No effect.<br>
<br>
I didn't see any obvious systematic problems with the libraries that<br>
didn't load (I focussed on libmemoryprovider, because that one is<br>
relatively simple), and neither in the ldd nor readelf outputs did<br>
anything stand out as an obvious red flag. (I say 'obvious red flag'<br>
because I lack the expertise to properly understand even half the<br>
things that come out of readelf, and can only look for a limited<br>
number of 'telltale signs')<br>
<br>
So.. what am I missing? Is there some other library that Qgis preloads<br>
that makes the loading of the other dynamically linked providers work?<br>
And how can I get that to also happen from a regular python script not<br>
inside the embedded python console?<br>
<br>
<br>
Kind regards,<br>
Nils<br>
_______________________________________________<br>
Qgis-user mailing list<br>
<a href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-<br>Gary Sherman<br>Chair, QGIS Project Steering Committee<br>-Desktop GIS Book:<br> *<a href="http://desktopgisbook.com" target="_blank">http://desktopgisbook.com</a><div>
-Alaska Novel:</div><div> *<a href="http://alaskana.co" target="_blank">http://alaskana.co</a></div><div>-Geospatial Consulting & Hosting:<br> *<a href="http://geoapt.com" target="_blank">http://geoapt.com</a><br>"We work virtually everywhere"<br>
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-</div>
</div>