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