Error Importing MySQLdb

D

David George

Hello there,
I have been trying for awhile now to get MySQLdb working. I am currently
getting this error when trying to import it:

Traceback (most recent call last): File "", line 1, in File
"build/bdist.macosx-10.7-intel/egg/MySQLdb/init.py", line 19, in File
"build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in File
"build/bdist.macosx-10.7-intel/egg/_mysql.py", line 6, in bootstrap
ImportError:
dlopen(/Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so,
2): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib
Referenced from:
/Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
Reason: image not found

Anyone know what I need to do in order to correct these errors.

Thanks
 
B

Benjamin Kaplan

Hello there,
I have been trying for awhile now to get MySQLdb working. I am currently
getting this error when trying to import it:


Traceback (most recent call last): File "", line 1, in File
"build/bdist.macosx-10.7-intel/egg/MySQLdb/init.py", line 19, in File
"build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in File
"build/bdist.macosx-10.7-intel/egg/_mysql.py", line 6, in bootstrap
ImportError:
dlopen(/Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so,
2): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib Referenced
from:
/Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
Reason: image not found

Anyone know what I need to do in order to correct these errors.

Thanks

MySQLdb is having trouble loading the MySQL client library. Since I
assume MySQL is installed, my best guess is that you have an
architecture problem. Your Python is probably running in 64-bit mode.
Do you have a 64-bit MySQL install? The "file" command will tell you
which architectures are in a binary if you're unsure.
 
D

davidfx

I am not sure what file you mean. Where should I look for the file you are talking about? By the way MySQL works fine within MAMP.

Thanks for your suggestions.
 
D

davidfx

I am not sure what file you mean. Where should I look for the file you are talking about? By the way MySQL works fine within MAMP.

Thanks for your suggestions.
 
D

Dave Angel

I am not sure what file you mean. Where should I look for the file you are talking about? By the way MySQL works fine within MAMP.

Thanks for your suggestions.
In most Linux/Unix systems, there is a file utility on the system PATH.

To find the type of a particular file, you run it as
file unknowndata

and it'll use its heuristics to guess what kind of data you have,
written by what software, or what type of executable you have, and
whether it's 32 bit or 64, etc.
 
B

Benjamin Kaplan

I am not sure what file you mean.  Where should I look for the file youare talking about?  By the way MySQL works fine within MAMP.

Thanks for your suggestions.


Like I said, it's likely an architecture issue. If you have a 32-bit
MySQL install and are using a 64-bit Python, it won't be able to load
the client libraries. The Python install included in Lion is universal
(a single file containing both 32-bit and 64-bit executables) so if
it's loaded by a 32-bit program, it will load in 32-bit mode.

"file" is a command that uses heuristics to determine the type of a
file. You run it from a terminal.

$ file /usr/bin/python
/usr/bin/python: Mach-O universal binary with 2 architectures
/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386

Try running "file /usr/local/lib/libmysqlclient.18.dylib". According
to the traceback you posted, that's the library that failed to load.

If you need to force Python to run in 32-bit mode, you can use the arch command
"arch -i386 python"
 
J

John Nagle

Like I said, it's likely an architecture issue. If you have a 32-bit
MySQL install and are using a 64-bit Python, it won't be able to load
the client libraries. The Python install included in Lion is universal
(a single file containing both 32-bit and 64-bit executables) so if
it's loaded by a 32-bit program, it will load in 32-bit mode.

Actually, the issue is only whether you have 64-bit MySQL client
libraries for C to which MySQLdb can link. Those are called
"MySQL Connector/C", and here are the download pages for them.

http://dev.mysql.com/downloads/connector/c/

The actual database can (and usually should be) the 64-bit executable,
while the libraries can be 32 or 64 bit. They communicate over a socket,
and don't even need to be on the same machine.

Unfortunately, the whole MySQLdb/Python/Connector/C versioning
setup is a mess. See:

http://chaos.weblogs.us/archives/327

John Nagle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top