python mysqldb problem interfacing with python 2.6 & or mysql

I have MYSQL & MYSQLdb installed with Python 2.6 & Django 1.2.3. I can open & log on to mysql no problem but it's not interfacing with python when I check to see if it's working properly in the python interpreter. This is the error msg I am getting when I invoke it in the interpreter....

import MySQLdb

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/_mysql.so, 2): Library not loaded: /opt/local/lib/mysql5/mysql/libmysqlclient_r.15.dylib
  Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/_mysql.so
  Reason: image not found

Answers


Looks like you are using a MacPorts Python installation on MacOS X. If you use MacPorts properly to upgrade, you should not run into problems like that. First, make sure your installation is up-to-date:

$ sudo port selfupdate
$ sudo port outdated   # lists outdated ports
$ sudo port -u upgrade outdated  # upgrade outdated ports and remove old versions

Then, if you still have problems, make sure you don't have a file permission problem somewhere. It should look something like this:

$ ls -l /opt/local/lib/mysql5/mysql
total 93824
-rw-r--r--  2 root  admin      1824 Nov 22 16:10 libdbug.a
-rw-r--r--  2 root  admin    161176 Nov 22 16:10 libheap.a
-rw-r--r--  2 root  admin    900552 Nov 22 16:10 libmyisam.a
-rw-r--r--  2 root  admin    136472 Nov 22 16:10 libmyisammrg.a
-rwxr-xr-x  2 root  admin   2871400 Nov 22 16:10 libmysqlclient.16.dylib*
-rw-r--r--  2 root  admin   3224032 Nov 22 16:10 libmysqlclient.a
lrwxr-xr-x  1 root  admin        23 Nov 22 16:10 libmysqlclient.dylib@ -> libmysqlclient.16.dylib
-rwxr-xr-x  2 root  admin      1028 Nov 22 16:10 libmysqlclient.la*
-rwxr-xr-x  2 root  admin   2891208 Nov 22 16:10 libmysqlclient_r.16.dylib*
-rw-r--r--  2 root  admin   3248504 Nov 22 16:10 libmysqlclient_r.a
lrwxr-xr-x  1 root  admin        25 Nov 22 16:10 libmysqlclient_r.dylib@ -> libmysqlclient_r.16.dylib
-rwxr-xr-x  2 root  admin      1040 Nov 22 16:10 libmysqlclient_r.la*
-rw-r--r--  2 root  admin  25939344 Nov 22 16:10 libmysqld.a
-rw-r--r--  2 root  admin   2643984 Nov 22 16:10 libmystrings.a
-rw-r--r--  2 root  admin    667720 Nov 22 16:10 libmysys.a
-rwxr-xr-x  2 root  admin   2039856 Nov 22 16:10 libndbclient.3.dylib*
-rw-r--r--  2 root  admin   3221192 Nov 22 16:10 libndbclient.a
lrwxr-xr-x  1 root  admin        20 Nov 22 16:10 libndbclient.dylib@ -> libndbclient.3.dylib
-rwxr-xr-x  2 root  admin       976 Nov 22 16:10 libndbclient.la*
-rw-r--r--  2 root  admin     29568 Nov 22 16:10 libvio.a
drwxr-xr-x  2 root  admin       612 Nov 22 16:10 plugin/

Also make sure you don't have an architecture mismatch:

$ cd /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
$ file _mysql.so
_mysql.so: Mach-O universal binary with 2 architectures
_mysql.so (for architecture x86_64):    Mach-O 64-bit bundle x86_64
_mysql.so (for architecture i386):  Mach-O bundle i386
$ otool -L _mysql.so  # this shows which MySQL client lib the Python DB adapter is dynamically linked to
_mysql.so:
    /opt/local/lib/mysql5/mysql/libmysqlclient_r.16.dylib (compatibility version 17.0.0, current version 17.0.0)
    /opt/local/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
    /opt/local/lib/libssl.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8)
    /opt/local/lib/libcrypto.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8)
$ cd /opt/local/lib/mysql5/mysql/
$ file libmysqlclient_r.16.dylib 
libmysqlclient_r.16.dylib: Mach-O universal binary with 2 architectures
libmysqlclient_r.16.dylib (for architecture i386):  Mach-O dynamically linked shared library i386
libmysqlclient_r.16.dylib (for architecture x86_64):    Mach-O 64-bit dynamically linked shared library x86_64

And, of course, make sure you are really using the MacPorts Python:

$ /opt/local/bin/python2.6 -V
Python 2.6.6
$ /opt/local/bin/python2.6 -c 'import MySQLdb; print(MySQLdb._mysql.__file__)'
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated
  from sets import ImmutableSet
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/_mysql.so

Python can not find the 'libmysqlclient_r.15.dylib' file. You might have mismatched versions of MySQL and MYSQLdb, or that file is not in a standard place. Try reinstalling MYSQLdb.


Need Your Help

ASP.NET Get value from DropDownList in EditItemTemplate in codebehind

c# asp.net

I have a GridView that I have placed in DropDownList's in 2 columns.

windows phone 7 keep application running on back button

c# windows-phone-7 application-state

I'm implementing an application that should not stop running on clicking any button on the device. Is this possible and how can I achieve this?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.