[Qgis-user] Error importing qgis in python
woklist at kyngchaos.com
Thu Nov 5 13:04:36 EST 2009
On Nov 5, 2009, at 10:47 AM, Daniel Arribas-Bel wrote:
> That was my impression, Giovanni. But when I do as suggested in your
> link, I get the following error:
> dhcp-184-245:~ dreamessence$ python
> Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
> [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import qgis.core
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ImportError: dlopen(/Applications/qgis1.0.0.app/Contents/MacOS/share/
> qgis/python/qgis/core.so, 2): Library not loaded: @executable_path/
> Referenced from: /Applications/qgis1.0.0.app/Contents/MacOS/share/
> Reason: image not found
> Any suggestion why this happens?
> On Thu, Nov 5, 2009 at 4:53 PM, G. Allegri <giohappy at gmail.com> wrote:
> > I believe the Python features of Qgis are supposed to be used from
> within Qgis, either in plugins or the builtin python console. It
> >certainly is compiled that way, even if it is supposed to be
> That's not true. If you correctly setup the environment (path to qgis
> libraries, python modules, etc.) you can use qgis functionalities
> within python without starting up qgis itself.
> Look at here: http://desktopgisbook.com/Creating_a_Standalone_GIS_Application_1
It was a guess with a disclaimer... All the internal libraries and
frameworks are relatively linked to the Qgis application binary - the
'@executable_path' in the error above. When an external python
interpreter is used, it won't find them.
The instructions in that link have a small problem: LD_LIBRARY_PATH is
DYLD_LIBRARY_PATH on OSX (though it's possible LD_LIBRARY_PATH also
works). Normally this would take care of the linker finding alternate
copies of libraries and frameworks. If DYLD_LIBRARY_PATH doesn't
help, it's possible there is a problem with that Qgis build.
Try installing Qgis 1.3. I just tested it on Leopard and it works:
>>> import PyQt4.QtCore
>>> import PyQt4.QtGui
>>> import qgis.core
>>> import qgis.gui
One note: from that python version 2.5.2, I'm guessing you're using
the python.org python, instead of the system python (2.5.1). That
Qgis 1.0 (Tom's old all-in-one) may be compiled to use that, but later
versions of Qgis (my builds) use the system Python. The way the Qgis
python library is made, it links to a specific python binary. It may
work externally, since the Qgis python library is only loaded by the
application, but the Qgis application will not use the python.org
Python, nor any python modules you may have installed there.
William Kyngesburye <kyngchaos*at*kyngchaos*dot*com>
The equator is so long, it could encircle the earth completely once.
More information about the Qgis-user