Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am interested in learning how to write standalone scripts using QGIS. An answer to my previous question directed me to the PyGIS CookBook which has the following instructions for importing the library in python:

from qgis.core import *

I am using a Mac with OSX 10.7.4. To set the library and pythonpath, I used the following commands in my terminal, based on advice on this mailing list:

export DYLD_LIBRARY_PATH=/Applications/Qgis.app/Contents/MacOS/lib:/Applications/Qgis.app/Contents/Frameworks
export PYTHONPATH=/Applications/Qgis.app/Contents/Resources/python 

Then, when I started python and typed from qgis.core import * I got the following error message:

python: VERSIONER_PYTHON_VERSION environment variable error (ignored)
Python 2.6.7 (r267:88850, Jul 31 2011, 19:30:54) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from qgis.core import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Applications/Qgis.app/Contents/Resources/python/qgis/core.so, 2): Symbol not found: _PyCapsule_Type
  Referenced from: /Applications/Qgis.app/Contents/Resources/python/qgis/core.so
  Expected in: flat namespace
 in /Applications/Qgis.app/Contents/Resources/python/qgis/core.so

Am I setting the paths correctly? I visually checked these and they appear to make sense based on what is in the folder, but I'm not familiar enough with this to know if there is a problem or not.

Edit: In response to @lynxlynxlynx inquiring if a more recent version of python solved the problem, I got a different error message.

When using QGIS, I checked the python version and saw the following message:

>>>sys.version_info
sys.version_info(major=2, minor=7, micro=1, releaselevel='final', serial=0)

In my terminal I get the following message:

>>> sys.version_info
sys.version_info(major=2, minor=7, micro=2, releaselevel='final', serial=0)

If I trying using Python 2.7.2, I get a different error message:

Python 2.7.2 |EPD_free 7.2-2 (32-bit)| (default, Sep  7 2011, 09:16:50) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "packages", "demo", "upgrade" or "enthought" for more information.
>>> from qgis.core import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Applications/Qgis.app/Contents/Resources/python/qgis/core.so, 2): no suitable image found.  Did find:
    /Applications/Qgis.app/Contents/Resources/python/qgis/core.so: mach-o, but wrong architecture
share|improve this question

1 Answer 1

up vote 2 down vote accepted

Symbol not found: _PyCapsule_Type

QGIS claims to work with python as low as 2.3 and while the PyCapsule module was introduced in 2.7 (as a backport from python 3.1), QGIS itself does not use it directly. The python bindings are generated by SIP during the build phase and if it thought PyCapsule will be available, it created different bindings. It decides by checking if SIP_USE_PYCAPSULE is defined.

You could muck around with recompiling with the symbol manually undefined or an older SIP, but for the first try, I suggest you get a newer version of python (2.7). It could automagically fix your problem.

share|improve this answer
    
hmmm, I was trying to use an earlier version of python as I get a wrong architecture when I use python 2.7. I'll update my question to include that error message too. –  djq Jul 22 '12 at 20:44
    
Isn't your system 64-bit (that's what wikipedia says lion supports only)? –  lynxlynxlynx Jul 22 '12 at 21:03
    
interesting, yes I just reinstalled python 2.7.3 and that fixed it! Not sure I fully understand why... but thanks for the assistance. –  djq Jul 22 '12 at 21:16
2  
You had a 32-bit python 2.7 installed before and you can't mix and match programs compiled for different architectures that easily. –  lynxlynxlynx Jul 22 '12 at 21:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.