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'm writing a QGIS Plugin, and somewhere I want to present data from a MySQL database. It's simple data(strings,etc), not Geospatial, or vector data. I'm familiar with querying databases from python scripts, and now I want to present data inside a TextBrowser QT Widget inside QGIS.

However, I can't import MySQLdb from built-in console, neither from my xxx.py file inside my plugin folder. From the Apple Terminal i can import MySQLdb with no problems.

I've read Why can't I import my script from the python console?, but still have no success, because when I call import MySQLdb inside a script that resides on a folder added to sys.path, it still fails.

Calling import MySQLdb from built-in console tells:

import MySQLdb
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 309, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "build/bdist.macosx-10.8-intel/egg/MySQLdb/__init__.py", line 19, in <module>
  File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 309, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "build/bdist.macosx-10.8-intel/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.8-intel/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/Arthur/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.8-intel.egg-tmp/_mysql.so, 2): no suitable image found.  Did find:
    /Users/Arthur/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.8-intel.egg-tmp/_mysql.so: mach-o, but wrong architecture

Thanks for reading!

ACKNOWLEDGE:

..mach-o, but wrong architecture -> this reveals a mismatch between python-mysqldb-mysql architecture!

The problem is that MySQLdb, does not support python2.7, as compiling for x86_64! Even if python and mysql-server are 64bits. Switching to python2.6, MySQLdb compiles a x86_64 binary; but QGIS 1.8 is built against python 2.7, so still does not work. Is it possible to select python framework inside QGIS?

This was very helpful -> http://stackoverflow.com/questions/12327737/error-importing-mysqldb-in-python-2-7-2-on-mac-osx-10-8-1

Thanks

share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.