Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MAMP Python-MySQLdb issue: Path to libssl.1.0.0.dylib changing once Python file called

I'm trying to use python MySQLdb to access my MySQL database on my MAMP server.

When I initially tried to call a Python file with python-sql to access my database on MAMP I got the image not found error regarding the libssl.1.0.0.dylib library

 Traceback (most recent call last):
  File "desktopsql.py", line 3, in <module>
    import _mysql as ms
  File "build/bdist.macosx-10.5-x86_64/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.5-x86_64/egg/_mysql.py", line 6, in __bootstrap__

  ImportError: 
   dlopen(/Users/username/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-
  10.5-x86_64.egg-tmp/_mysql.so, 2): 

  Library not loaded: libssl.1.0.0.dylib

  Referenced from: 
   /Users/username/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.5-x86_64.egg-tmp/_mysql.so

  Reason: image not found

So I fixed it to a certain extent by changing the libssl.1.0.0.dylib path using export DYLD_LIBRARY_PATH=/Users/username/anaconda/lib/:$DYLD_LIBRARY_PATH, but it has to be done for every folder I wish to execute the Python file in.

So when I try to execute the Python file through PHP on my MAMP webpage I get the error again, and I can't use my makeshift fix this time to cover it up.

I have tried to fix it further using install_name_tool to change the false library location /Users/username/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.5-x86_64.egg-tmp/_mysql.so to where it is actually stored in /Users/username/anaconda/lib/

sudo install_name_tool -change 
libssl.1.0.0.dylib 
/Users/username/anaconda/lib/libssl.1.0.0.dylib 
/Users/username/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.5-x86_64.egg-tmp/_mysql.so

After doing so I use otool -L to see the status of what I've changed and the result states that the file path has certainly changed to the correct location.

otool -L 
/Users/username/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.5-x86_64.egg-tmp/_mysql.so

    /Users/username/anaconda/lib/libssl.1.0.0.dylib 
    (compatibility version 1.0.0, current version 1.0.0)

However when I run the python file again, I get the image not found error. Upon running otool -L again the result shows that the file path has reverted back again.

/Users/username/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.5-x86_64.egg-tmp/_mysql.so:

    libssl.1.0.0.dylib 
    (compatibility version 1.0.0, current version 1.0.0)

So it changes to the correct location until I run the python file and it's back again to what it was before.

Why is this happening? Is there something I can do to make it maintain what I've changed it to?

like image 715
AnonyMouse Avatar asked Aug 30 '14 17:08

AnonyMouse


1 Answers

So I discovered I should be working with the libssl.1.0.0.dylib file in /usr/lib, not the file that was mentioned by the error, which was Users/$USERNAME/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.5-x86_64.egg-tmp/_mysql.so in my case.

I created a symlink to where libssl.1.0.0.dylib should be referenced from, (/Users/$USERNAME/anaconda/lib/ for me), using

sudo ln -s /Users/$USERNAME/anaconda/lib/libssl.1.0.0.dylib /usr/lib/libssl.1.0.0.dylib

and, once that's done, the same for libcrypto.1.0.0.dylib, as it threw the same error.

sudo ln -s /Users/$USERNAME/anaconda/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.1.0.0.dylib

As a side note when listing the files in /usr/bin these two are listed as libss.dylib and libcrypto.dylib.

like image 181
AnonyMouse Avatar answered Oct 05 '22 21:10

AnonyMouse