Sigh, how can this still be so hard in 2011? I downloaded the 64-bit version of MySQL:
http://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.5/mysql-5.5.14-osx10.6-x86_64.dmg
It’s all installed and running happily (not shown here but I can connect to db etc. too).
% set path=($path /usr/local/mysql/bin)
% mysql_config
…
--cflags [-I/usr/local/mysql/include -Os -g -fno-common -fno-strict-aliasing -arch x86_64]
--include [-I/usr/local/mysql/include]
--libs [-L/usr/local/mysql/lib -lmysqlclient -lpthread]
--libs_r [-L/usr/local/mysql/lib -lmysqlclient_r -lpthread]
--version [5.5.14]
--libmysqld-libs [-L/usr/local/mysql/lib -lmysqld -lpthread]
…
The client library exists and is 64-bit:
% lipo /usr/local/mysql/lib/libmysqlclient.dylib -info
Non-fat file: /usr/local/mysql/lib/libmysqlclient.dylib is architecture: x86_64
But even so, python can’t find the mysql client lib:
% python
Python 2.6.1 (r261:67515, Aug 2 2010, 20:10:18)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import MySQLdb
Traceback (most recent call last):
File “”, line 1, in
File “build/bdist.macosx-10.6-universal/egg/MySQLdb/init.py”, line 19, in
File “build/bdist.macosx-10.6-universal/egg/_mysql.py”, line 7, in
File “build/bdist.macosx-10.6-universal/egg/_mysql.py”, line 6, in bootstrap
ImportError: dlopen(/Users/leo.hourvitz/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/leo.hourvitz/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
Reason: image not found
>>> ^D
Is Python really running 64-bit? Looks like it:
% python
Python 2.6.1 (r261:67515, Aug 2 2010, 20:10:18)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import platform
>>> print platform.architecture()
(‘64bit’, “)
>>> ^D
%
What happened when I compiled, you ask? Some warnings, but the link command in particular looks perfectly sensible. I did the build in bash just to be sure I’m following the instructions above:
bash-3.2$ pwd
MySQL-python-1.2.3
bash-3.2$ PATH=“/usr/local/mysql/bin:$PATH”
bash-3.2$ ARCHFLAGS=“-arch x86_64” python setup.py build
running build
running build_py
creating build/lib.macosx-10.6-universal-2.6
copying _mysql_exceptions.py -> build/lib.macosx-10.6-universal-2.6
creating build/lib.macosx-10.6-universal-2.6/MySQLdb
copying MySQLdb/init.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb
copying MySQLdb/converters.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb
copying MySQLdb/connections.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb
copying MySQLdb/cursors.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb
copying MySQLdb/release.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb
copying MySQLdb/times.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb
creating build/lib.macosx-10.6-universal-2.6/MySQLdb/constants
copying MySQLdb/constants/init.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb/constants
running build_ext
building ‘_mysql’ extension
creating build/temp.macosx-10.6-universal-2.6
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,3,‘final’,0) -Dversion=1.2.3 -I/usr/local/mysql/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.6-universal-2.6/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch x86_64
In file included from _mysql.c:36:
/usr/local/mysql/include/my_config.h:330:1: warning: “SIZEOF_SIZE_T” redefined
In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:9,
from pymemcompat.h:10,
from _mysql.c:29:
/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pymacconfig.h:33:1: warning: this is the location of the previous definition
In file included from _mysql.c:36:
/usr/local/mysql/include/my_config.h:423:1: warning: “HAVE_WCSCOLL” redefined
In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:8,
from pymemcompat.h:10,
from _mysql.c:29:
/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyconfig.h:803:1: warning: this is the location of the previous definition
gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup build/temp.macosx-10.6-universal-2.6/_mysql.o -L/usr/local/mysql/lib -lmysqlclient_r -lpthread -o build/lib.macosx-10.6-universal-2.6/_mysql.so -arch x86_64
bash-3.2$
The output from setup.py install was clean with no errors.
It seems like the MySQLdb .so is not correctly referencing the mysql client library via the full absolute path. But isn’t it supposed to do that by itself?
This machine has been nowhere near Mac Ports.
Thanks for any help,
Leo
Comments
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,3,'gamma',1) -Dversion=1.2.3c1 -I/usr/local/mysql/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.6-universal-2.6/_mysql.o -g -Os -arch ppc64 -fno-common -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL
unable to execute gcc-4.2: No such file or directory
error: command 'gcc-4.2' failed with exit status 1
WHY??
..unable to execute gcc-4.2: No such file or directory
error: command 'gcc-4.2' failed with exit status 1
Check X-Code installation..
Mine is complaining about a lot of missing files:
core:MySQL-python-1.2.3c1 ayoung$ ARCHFLAGS='-arch x86_64' /usr/bin/python setup.py build
running build
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb
running build_ext
building '_mysql' extension
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -arch x86_64 -Dversion_info=(1,2,3,'gamma',1) -Dversion=1.2.3c1 -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.6-universal-2.6/_mysql.o -fno-omit-frame-pointer -pipe -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT
_mysql.c:36:23: error: my_config.h: No such file or directory
_mysql.c:38:19: error: mysql.h: No such file or directory
_mysql.c:39:26: error: mysqld_error.h: No such file or directory
_mysql.c:40:20: error: errmsg.h: No such file or directory
…
_mysql.c:2421: error: initializer element is not constant
_mysql.c:2421: error: (near initialization for ‘_mysql_ResultObject_memberlist[0].offset’)
_mysql.c: In function ‘_mysql_ConnectionObject_getattr’:
_mysql.c:2443: error: ‘_mysql_ConnectionObject’ has no member named ‘open’
error: command 'gcc-4.2' failed with exit status 1
core:MySQL-python-1.2.3c1 ayoung$
Try to install the tar ball distribution of MySQL for Mac OS X in /usr/local. Unpack it there and make sure the /usr/local/mysql symlink is in place.
Then try again with that version.
I did find a solution to my problem, it's not as elegant as I would desire, but that would depend on Apple releasing MySQL libs for 10.6 server.
I followed the directions for the 10.5 library download and install on this Apple kb article: http://support.apple.com/kb/TA25017
That got me where I needed to be to get django running as desired with a MySQL backend.
I’m getting this error:
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,3,‘final’,0) -Dversion=1.2.3 -I/usr/local/mysql/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.6-universal-2.6/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch x86_64 In file included from /usr/include/unistd.h:519, from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:44, from pymemcompat.h:10, from _mysql.c:29: /usr/include/sys/select.h:114: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before numeric constant In file included from _mysql.c:36: /usr/local/mysql/include/my_config.h:327:1: warning: “SIZEOF_SIZE_T” redefined In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:9, from pymemcompat.h:10, from _mysql.c:29: /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pymacconfig.h:33:1: warning: this is the location of the previous definition In file included from _mysql.c:36: /usr/local/mysql/include/my_config.h:420:1: warning: “HAVE_WCSCOLL” redefined In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:8, from pymemcompat.h:10, from _mysql.c:29: /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyconfig.h:803:1: warning: this is the location of the previous definition error: command ‘gcc-4.2’ failed with exit status 1
Any ideas?
Sigh, how can this still be so hard in 2011? I downloaded the 64-bit version of MySQL:
http://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.5/mysql-5.5.14-osx10.6-x86_64.dmg
It’s all installed and running happily (not shown here but I can connect to db etc. too).
% set path=($path /usr/local/mysql/bin) % mysql_config … --cflags [-I/usr/local/mysql/include -Os -g -fno-common -fno-strict-aliasing -arch x86_64] --include [-I/usr/local/mysql/include] --libs [-L/usr/local/mysql/lib -lmysqlclient -lpthread] --libs_r [-L/usr/local/mysql/lib -lmysqlclient_r -lpthread] --version [5.5.14] --libmysqld-libs [-L/usr/local/mysql/lib -lmysqld -lpthread] …
The client library exists and is 64-bit:
% lipo /usr/local/mysql/lib/libmysqlclient.dylib -info Non-fat file: /usr/local/mysql/lib/libmysqlclient.dylib is architecture: x86_64
But even so, python can’t find the mysql client lib:
% python Python 2.6.1 (r261:67515, Aug 2 2010, 20:10:18) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type “help”, “copyright”, “credits” or “license” for more information. >>> import MySQLdb Traceback (most recent call last): File “”, line 1, in File “build/bdist.macosx-10.6-universal/egg/MySQLdb/init.py”, line 19, in File “build/bdist.macosx-10.6-universal/egg/_mysql.py”, line 7, in File “build/bdist.macosx-10.6-universal/egg/_mysql.py”, line 6, in bootstrap ImportError: dlopen(/Users/leo.hourvitz/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib Referenced from: /Users/leo.hourvitz/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so Reason: image not found >>> ^D
Is Python really running 64-bit? Looks like it:
% python Python 2.6.1 (r261:67515, Aug 2 2010, 20:10:18) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type “help”, “copyright”, “credits” or “license” for more information. >>> import platform >>> print platform.architecture() (‘64bit’, “) >>> ^D %
What happened when I compiled, you ask? Some warnings, but the link command in particular looks perfectly sensible. I did the build in bash just to be sure I’m following the instructions above:
bash-3.2$ pwd MySQL-python-1.2.3 bash-3.2$ PATH=“/usr/local/mysql/bin:$PATH” bash-3.2$ ARCHFLAGS=“-arch x86_64” python setup.py build running build running build_py creating build/lib.macosx-10.6-universal-2.6 copying _mysql_exceptions.py -> build/lib.macosx-10.6-universal-2.6 creating build/lib.macosx-10.6-universal-2.6/MySQLdb copying MySQLdb/init.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb copying MySQLdb/converters.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb copying MySQLdb/connections.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb copying MySQLdb/cursors.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb copying MySQLdb/release.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb copying MySQLdb/times.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb creating build/lib.macosx-10.6-universal-2.6/MySQLdb/constants copying MySQLdb/constants/init.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb/constants copying MySQLdb/constants/CR.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb/constants copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb/constants copying MySQLdb/constants/ER.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb/constants copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb/constants copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb/constants copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb/constants running build_ext building ‘_mysql’ extension creating build/temp.macosx-10.6-universal-2.6 gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,3,‘final’,0) -Dversion=1.2.3 -I/usr/local/mysql/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.6-universal-2.6/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch x86_64 In file included from _mysql.c:36: /usr/local/mysql/include/my_config.h:330:1: warning: “SIZEOF_SIZE_T” redefined In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:9, from pymemcompat.h:10, from _mysql.c:29: /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pymacconfig.h:33:1: warning: this is the location of the previous definition In file included from _mysql.c:36: /usr/local/mysql/include/my_config.h:423:1: warning: “HAVE_WCSCOLL” redefined In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:8, from pymemcompat.h:10, from _mysql.c:29: /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyconfig.h:803:1: warning: this is the location of the previous definition gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup build/temp.macosx-10.6-universal-2.6/_mysql.o -L/usr/local/mysql/lib -lmysqlclient_r -lpthread -o build/lib.macosx-10.6-universal-2.6/_mysql.so -arch x86_64
bash-3.2$
The output from setup.py install was clean with no errors.
It seems like the MySQLdb .so is not correctly referencing the mysql client library via the full absolute path. But isn’t it supposed to do that by itself?
This machine has been nowhere near Mac Ports.
Thanks for any help,
Leo
@leovitch To get you going, you can do like this: shell> DYLD_LIBRARY_PATH=“/usr/local/mysql/lib” python python> import MySQLdb
Not sure still what is wrong. Doing more steps than what I blogged is just annoyance. Maybe you can google to solution though? I’ll check later more.
Geert,
Thanks, I knew there was some variable like that and the above does let me load MySQLdb for test purposes. Of course since I’m installing this for the sake of a web app and fiddling with DYLD_LIBRARY_PATH in my Apache is a bit sketchy, I’m trying to find the real solution. It seems like the crux of it must be the link command, huh?
Leo
FWIW, otool does seem to show the built _mysql.so has a relative rather than absolute path in it:
% otool -L build/lib.macosx-10.6-universal-2.6/_mysql.so build/lib.macosx-10.6-universal-2.6/_mysql.so: 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.2.11)
Is that expected?
Leo
I found a workaround although it still feels like something must be going wrong if this extra step is required.
After building, as mentioned before, the _mysql.o has a relative path:
% otool -L build/lib.macosx-10.6-universal-2.6/_mysql.so build/lib.macosx-10.6-universal-2.6/_mysql.so: 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.2.11)
So I use install_name_tool to change it as suggested at http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/:
% install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib build/lib.macosx-10.6-universal-2.6/_mysql.so
And sure enough it’s absolute afterwards:
% otool -L build/lib.macosx-10.6-universal-2.6/_mysql.so build/lib.macosx-10.6-universal-2.6/_mysql.so: /usr/local/mysql/lib/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.2.11)
And sure enough if I reinstall that, it works without DYLD_LIBRARY_PATH:
% python Python 2.6.1 (r261:67515, Aug 2 2010, 20:10:18) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type “help”, “copyright”, “credits” or “license” for more information. >>> import MySQLdb /Library/Python/2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /Library/Python/2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg/_mysql.pyc, but /Users/leovitch/src/MySQL-python-1.2.3 is being added to sys.path >>> ^D
I’m not sure what the origin of the warning message is -- why should my build directory be added to sys.path? -- but it seems like this at least gets the module installed correctly.