Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7008267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:42:47+00:00 2026-05-27T21:42:47+00:00

I want to get MySQL working with the system Python 2.7 in Mac OS

  • 0

I want to get MySQL working with the system Python 2.7 in Mac OS X Lion.

I know there are a lot of questions very similar to this out there, and in fact my symptom is identical to mysql-python installation problems (on mac os x lion). However, that answer doesn’t seem to apply to my case.

My Mac is a current MacBook Pro running the 64-bit kernel:

% uname -a 
Darwin Leos-MacBook-Pro.local 11.2.0 Darwin Kernel Version 11.2.0: Tue Aug  9 20:54:00 PDT 2011; root:xnu-1699.24.8~1/RELEASE_X86_64 x86_64

The stock python on Lion is a fat binary:

% 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

I had used Migration Assistant so my system had an old installation of MySQL on it. I used the instructions at How to remove installation of MySQL on Mac OS X to remove the old MySQL installation.

MySQL 64-bit 5.5.19 was installed from the .dmg on the MySQL site. As usual, this placed the client library in /usr/local/mysql/lib. The client library appears to be exactly what we want:

% file /usr/local/mysql/lib/libmysqlclient.18.dylib
/usr/local/mysql/lib/libmysqlclient.18.dylib: Mach-O 64-bit dynamically linked shared library x86_64

However, that shared library can’t be loaded into python (I’m using the arch command to make absolutely sure I’m running the 64-bit image although the result is the same with or without that):

% arch -x86_64 python
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import cdll
>>> cdll.LoadLibrary("/usr/local/mysql/lib/libmysqlclient.18.dylib")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 431, in LoadLibrary
    return self._dlltype(name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 353, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/usr/local/mysql/lib/libmysqlclient.18.dylib, 6): no suitable image found.      Did find:
    /usr/local/mysql/lib//libmysqlclient.18.dylib: mach-o, but wrong architecture
    /usr/local/mysql/lib/libmysqlclient.18.dylib: mach-o, but wrong architecture

I can reproduce this problem many other ways, notably by using the standard import MySQLdb; I’m showing the ctypes way of reproducing the bug specifically because I was trying to figure out whether the problem was in mysql-python or in the MySQL client library. From the above, it seems to be the client library. However, I’m baffled as to why the loader thinks the client library is the wrong architecture.

In trying to see whether it’s some dependent library that’s the problem, I checked the dependencies in libmysqlclient.18.dylib:

% otool -L /usr/local/mysql/lib/libmysqlclient.18.dylib
/usr/local/mysql/lib/libmysqlclient.18.dylib:
libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.0.1)

And of course /usr/lib/libSystemB.dylib is a fat binary as expected:

% file /usr/lib/libSystem.B.dylib 
/usr/lib/libSystem.B.dylib: Mach-O universal binary with 2 architectures
/usr/lib/libSystem.B.dylib (for architecture x86_64):   Mach-O 64-bit dynamically linked shared library x86_64
/usr/lib/libSystem.B.dylib (for architecture i386): Mach-O dynamically linked shared library i386

So… Python is 64-bit, the mysqlclient library is 64-bit, and the dependent libraries are all 64-bit… Any guesses as to why the loader is refusing the import the library would be very welcome.

Just for the belt-and-suspenders checking that everything’s 64-bit-y:

% python -c 'import platform; print platform.platform()'
Darwin-11.2.0-x86_64-i386-64bit
% ls -l /usr/local/mysql
lrwxr-xr-x  1 root  wheel  27 Dec 10 16:52 /usr/local/mysql@ -> mysql-5.5.19-osx10.6-x86_64

At this point, since I need to actually get some work done, I’m going to try switching to pymysql. This is mostly for use with Django, for which there’s a convenient way to swap pymysql in documented at the bottom of this thread.

P.S. I understand macports and can’t use it on this system.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:42:47+00:00Added an answer on May 27, 2026 at 9:42 pm

    Chances are you have set the default execution mode of the Apple-supplied Python to 32-bits, either by using defaults or by setting the VERSIONER_PYTHON_PREFER_32_BIT environment variable; see man python for details. In OS X 10.6 and 10.7 /usr/bin/python is an Apple-supplied wrapper program that determines which Python to run and in which mode. Using arch to execute /usr/bin/python will not influence the interpreter. For example:

    $ unset VERSIONER_PYTHON_PREFER_32_BIT 
    $ arch -x86_64 /usr/bin/python -c "import sys;print(sys.maxsize)"
    9223372036854775807
    $ export VERSIONER_PYTHON_PREFER_32_BIT=yes
    $ arch -x86_64 /usr/bin/python -c "import sys;print(sys.maxsize)"
    2147483647
    #
    # But avoiding the wrapper program ....
    #
    $ arch -x86_64 /usr/bin/python2.7 -c "import sys;print(sys.maxsize)"
    9223372036854775807
    $ arch -i386 /usr/bin/python2.7 -c "import sys;print(sys.maxsize)"
    2147483647
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning mysql and have been trying to get this working, but an error
This is a recent problem... MySQL was working and a couple of days ago
Can you get the true MIN/MAX of a date/time using this on MySQL? MAX(CONCAT(`Date`,
I cant seem to get this working, i need to display the Total Order
I want to make a simple news system using PHP and MySQL, right now
I'm working on a messaging system and want the user's userid to be posted
I'm working on a shop-like system (in PHP & MySQL) that exports invoices to
I'm working on a project where we want to write to a mysql database,
Working with Visual Studio, Windows 7 and mysql.h library. What I want to do
This is for a sort of proof of concept draft to get things working,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.