Error importing qgis in python

6 messages Options
Embed this post
Permalink
Daniel Arribas-Bel

Error importing qgis in python

Reply Threaded More More options
Print post
Permalink
Hi All!

I'm trying to import qgis into python outside the standard qgis python console. I've set ht PYTHONPATH like the following:

export PYTHONPATH=${PYTHONPATH}:"/Applications/qgis1.0.0.app/Contents/MacOS/share/qgis/python/"
Then I fire up a fresh terminal, open ipython and try to import it getting the following:

In [3]: import qgis.core
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)

/Users/dreamessence/<ipython console> in <module>()

ImportError: dlopen(/Applications/qgis1.0.0.app/Contents/MacOS/share/qgis/python/qgis/core.so, 2): Library not loaded: @executable_path/lib/libqgis_core.1.0.dylib
  Referenced from: /Applications/qgis1.0.0.app/Contents/MacOS/share/qgis/python/qgis/core.so
  Reason: image not found

In [4]:

Any suggestions/ideas why it's happening? How could I make it work? If I'm on the python console within qgis it works fine.

I'm on MacOS 10.5 and qGIS-1.0.0

Thank you very much,

]d[

--
============================================================
Daniel Arribas-Bel
Url: darribas.org
Mail: [hidden email]

Department of Economic Analysis
Universidad de Zaragoza (www.unizar.es)

GeoDa Center for Geospatial Analysis and Computation (geodacenter.asu.edu)
Arizona State University (USA)
============================================================


_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user
William Kyngesburye

Re: Error importing qgis in python

Reply Threaded More More options
Print post
Permalink
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 possible.

On Nov 5, 2009, at 8:24 AM, Daniel Arribas-Bel wrote:

> Hi All!
>
> I'm trying to import qgis into python outside the standard qgis  
> python console. I've set ht PYTHONPATH like the following:
>
> export PYTHONPATH=${PYTHONPATH}:"/Applications/qgis1.0.0.app/
> Contents/MacOS/share/qgis/python/"
> Then I fire up a fresh terminal, open ipython and try to import it  
> getting the following:
>
> In [3]: import qgis.core
> ---------------------------------------------------------------------------
> ImportError                               Traceback (most recent  
> call last)
>
> /Users/dreamessence/<ipython console> in <module>()
>
> ImportError: dlopen(/Applications/qgis1.0.0.app/Contents/MacOS/share/
> qgis/python/qgis/core.so, 2): Library not loaded: @executable_path/
> lib/libqgis_core.1.0.dylib
>   Referenced from: /Applications/qgis1.0.0.app/Contents/MacOS/share/
> qgis/python/qgis/core.so
>   Reason: image not found
>
> In [4]:
>
> Any suggestions/ideas why it's happening? How could I make it work?  
> If I'm on the python console within qgis it works fine.
>
> I'm on MacOS 10.5 and qGIS-1.0.0
>
> Thank you very much,
>
> ]d[
>
> --
> ============================================================
> Daniel Arribas-Bel
> Url: darribas.org
> Mail: [hidden email]
>
> Department of Economic Analysis
> Universidad de Zaragoza (www.unizar.es)
>
> GeoDa Center for Geospatial Analysis and Computation (geodacenter.asu.edu
> )
> Arizona State University (USA)
> ============================================================
>
> _______________________________________________
> Qgis-user mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/qgis-user

-----
William Kyngesburye <kyngchaos*at*kyngchaos*dot*com>
http://www.kyngchaos.com/

"We are at war with them. Neither in hatred nor revenge and with no  
particular pleasure I shall kill every ___ I can until the war is  
over. That is my duty."

"Don't you even hate 'em?"

"What good would it do if I did? If all the many millions of people of  
the allied nations devoted an entire year exclusively to hating the  
____ it wouldn't kill one ___ nor shorten the war one day."

<Ha, ha> "And it might give 'em all stomach ulcers."

- Tarzan, on war

_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user
Greg Coats

TIFF tag 33723 IPTC metadata

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
When Photoshop writes a .tif file, it automatically includes TIFF tag 700 XMP metadata, and TIFF tag 33723 IPTC metadata. The TIFF utilities tiffcp and geotifcp copy these Photoshop created .tif files. For example, the commands below read in image1.tif, and then write image2.tif, arranged into tiles 256x256, and include the XMP and IPTC metadata.
$ tiffcp   -t -w 256 -l 256 image1.tif image2.tif
$ geotifcp -t -w 256 -l 256 image1.tif image2.tif 

The (unofficial ?) web page
identifies TIFF tag 33723 IPTC as Type=UNDEFINED or 7, and yet tiffinfo shows that the Photoshop created .tif files have TIFF tag 33723 IPTC written as Type=LONG or 4. Why this difference?

The Kakadu version 6.3.0 supports reading and writing TIFF tag 700 XMP metadata, and TIFF tag 33723 IPTC metadata. There is no problem with XMP metadata, but when writing IPTC metadata, kdu_expand writes TIFF tag 33723 IPTC as Type=UNDEFINED or 7, in compliance with the awaresystems web page.

But then I observe that tiffcp and geotifcp both report the Kakadu written .tif has an "Incompatible type" for its TIFF tag 33723 IPTC metadata, even though the type conforms to the awaresystems web page, although that is different from what Adobe uses in Photoshop, and as a result the IPTC metadata is lost, and not included in the output .tif file.

$ geotifcp -t -w 256 -l 256 image01_v6_3_x86_03_64.tif image01_v6_3_x86_03_64_kduV630_1.tif
TIFFFetchNormalTag: Warning, Incompatible type for "RichTIFFIPTC"; tag ignored.

Should I change the Kakadu source code so that it makes the same mistake Photoshop makes, and identifies TIFF tag 33723 IPTC metadata as Type=LONG or 4?
Greg

_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user
giohappy

Re: Error importing qgis in python

Reply Threaded More More options
Print post
Permalink
In reply to this post by William Kyngesburye
> 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 possible.

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

bye,
giovanni
_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user
Daniel Arribas-Bel

Re: Error importing qgis in python

Reply Threaded More More options
Print post
Permalink
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/lib/libqgis_core.1.0.dylib
  Referenced from: /Applications/qgis1.0.0.app/Contents/MacOS/share/qgis/python/qgis/core.so
  Reason: image not found
>>>

Any suggestion why this happens?

Thanks a bunch,

]d[

On Thu, Nov 5, 2009 at 4:53 PM, G. Allegri <[hidden email]> 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 possible.

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

bye,
giovanni



--
============================================================
Daniel Arribas-Bel
Url: darribas.org
Mail: [hidden email]

Department of Economic Analysis
Universidad de Zaragoza (www.unizar.es)

GeoDa Center for Geospatial Analysis and Computation (geodacenter.asu.edu)
Arizona State University (USA)
============================================================


_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user
William Kyngesburye

Re: Error importing qgis in python

Reply Threaded More More options
Print post
Permalink
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/
> lib/libqgis_core.1.0.dylib
>   Referenced from: /Applications/qgis1.0.0.app/Contents/MacOS/share/
> qgis/python/qgis/core.so
>   Reason: image not found
> >>>
>
> Any suggestion why this happens?
>

> On Thu, Nov 5, 2009 at 4:53 PM, G. Allegri <[hidden email]> 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  
> possible.
>
> 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
>
> bye,
> giovanni

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:

export DYLD_LIBRARY_PATH=/Applications/Qgis.app/Contents/MacOS/lib:/
Applications/Qgis.app/Contents/Frameworks
export PYTHONPATH=/Applications/Qgis.app/Contents/Resources/python
python
 >>> 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>
http://www.kyngchaos.com/

The equator is so long, it could encircle the earth completely once.

_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user