2

I am new to mac and to python. I have installed mysqldb for python mac. But when i try to import it, this is the error i am getting :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.6/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/Library/Python/2.6/site-packages/_mysql.so, 2): Symbol not found: _strnlen
  Referenced from: /usr/lib/libmysqlclient.18.dylib
  Expected in: /usr/lib/libSystem.B.dylib
 in /usr/lib/libmysqlclient.18.dylib

Why am i getting this error? How do i resolve it? I have tried a crazy number of answers posted here on SO but nothing seems to work. What should i do to resolve this error?

Thanks.

Nikhil
  • 1,279
  • 2
  • 23
  • 43
  • How did you install mysql? (And how did you get it into /usr/lib?) How did you install the Python module? Which version of OS X do you have? – abarnert Sep 25 '13 at 18:36
  • 1)I googled how to unhide the usr directory on mac. and then got into it. mysql was already installed on the mac. i think using wampp. 2)python2.6 was already installed on this machine that I got to work on. If you are asking how i installed mysqldb,I downloaded a zip file and ran setup.py (Read instructions on SO) 3) I have version 10.6.8 Now,can you help me? – Nikhil Sep 25 '13 at 18:48
  • Python2.6 comes built-in on OS X. MySQL doesn't, and neither does the Python mysqldb module. Anyway, just telling me "i think using wampp" and "downloaded a zip file" doesn't tell me nearly enough to diagnose the problem. Clearly something got built wrong, but I have no idea what, or why, and you've given me no way to reproduce it or recognize a known problem or anything. So, all I can say is, uninstall and reinstall them. – abarnert Sep 25 '13 at 19:07
  • 1)To be precise, I followed the steps here: http://stackoverflow.com/questions/1448429/how-to-install-mysqldb-python-data-access-library-to-mysql-on-mac-os-x See the answer with 74 upvotes. 2)I have already uninstalled and again installed using pip >>pip install mysqldb-python Is there anything else that would help you diagnose this? – Nikhil Sep 25 '13 at 19:10
  • Meaning you downloaded and installed the 32-bit MySQL from [here](http://dev.mysql.com/downloads/mysql/5.1.html#macosx-dmg), or just steps 1-10 using some other MySQL installation? – abarnert Sep 25 '13 at 19:20
  • 1)Only steps from 1 to 10 using some other MySql Installation 2)Do you want to know which mysql i have on my system? I don't know..I'll have to figure that out. 3)However, I wish to connect to a remote mysql DB – Nikhil Sep 25 '13 at 19:33
  • The issue isn't the MySQL server, it's the libmysqlclient that you link against. For example, you might have built against a different version than you use at runtime. Or it might have been built against a different C library than the one Python and your module are built against. Etc. – abarnert Sep 25 '13 at 19:41
  • Okay...How can I resolve that now? I am not familiar about this linking stuff. I just followed the steps listed over there. – Nikhil Sep 25 '13 at 19:44
  • My guess is that the problem is with your mysql libs. After all, you've tried two different ways to build the Python bindings against it, both of which seem reasonable, and they both failed. So, you're going to need to figure out where you got the mysql libs from, and most likely reinstall them. – abarnert Sep 25 '13 at 20:14

1 Answers1

0

Did you use sudo when you installed?

sudo pip install mysql-python

Then add this line to your ~/.bash_profile

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
beroe
  • 11,784
  • 5
  • 34
  • 79
  • I did use the above stuff. I was getting a different error then..so no.. this did not work for me either.. – Nikhil Sep 28 '13 at 04:16