Installing oursql on Mac OS Lion succeeds, but importing into python fails. **What for?**

I followed the installation instructions to install oursql on Mac OS X. Since

sudo pip install oursql 

told me that he could not find mysql_config i (located with locate mysql_config and), where he found it,

 sudo MYSQL_CONFIG=/usr/local/mysql-5.5.14-osx10.6-x86_64/bin/mysql_config pip install oursql 

I have added terminal output below for readability. After that I ran python in the terminal (on Mac OS Lion it is python 2.7 now, ...) and did

 >>> import oursql 

but python tells me:

 >>> import oursql Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: dlopen(/Library/Python/2.7/site-packages/oursql.so, 2): Library not loaded: libmysqlclient.18.dylib Referenced from: /Library/Python/2.7/site-packages/oursql.so Reason: image not found 

What am I missing? Any suggestions?


Output to the terminal to set the peak:

 Downloading/unpacking oursql Downloading oursql-0.9.2.tar.bz2 (113Kb): 113Kb downloaded Running setup.py egg_info for package oursql Installing collected packages: oursql Running setup.py install for oursql skipping 'oursqlx/oursql.c' Cython extension (up-to-date) building 'oursql' extension /usr/local/mysql-5.5.14-osx10.6-x86_64/bin/mysql_config --cflags llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c oursqlx/oursql.c -o build/temp.macosx-10.7-intel-2.7/oursqlx/oursql.o -I/usr/local/mysql-5.5.14-osx10.6-x86_64/include -Os -g -fno-common -fno-strict-aliasing -arch x86_64 oursqlx/oursql.c: In function '__pyx_pf_6oursql_10Connection___cinit__': oursqlx/oursql.c:4630: warning: implicit conversion shortens 64-bit value into a 32-bit value oursqlx/oursql.c: In function '__pyx_pf_6oursql_10_Statement_execute': oursqlx/oursql.c:10219: warning: implicit conversion shortens 64-bit value into a 32-bit value oursqlx/oursql.c: In function '__pyx_pf_6oursql_16_DBAPITypeObject___richcmp__': oursqlx/oursql.c:17597: warning: implicit conversion shortens 64-bit value into a 32-bit value llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c oursqlx/compat.c -o build/temp.macosx-10.7-intel-2.7/oursqlx/compat.o -I/usr/local/mysql-5.5.14-osx10.6-x86_64/include -Os -g -fno-common -fno-strict-aliasing -arch x86_64 /usr/local/mysql-5.5.14-osx10.6-x86_64/bin/mysql_config --libs llvm-gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup -Wl,-F. -arch i386 -arch x86_64 build/temp.macosx-10.7-intel-2.7/oursqlx/oursql.o build/temp.macosx-10.7-intel-2.7/oursqlx/compat.o -o build/lib.macosx-10.7-intel-2.7/oursql.so -L/usr/local/mysql-5.5.14-osx10.6-x86_64/lib -lmysqlclient -lpthread ld: warning: ignoring file build/temp.macosx-10.7-intel-2.7/oursqlx/oursql.o, file was built for unsupported file format which is not the architecture being linked (i386) ld: warning: ignoring file build/temp.macosx-10.7-intel-2.7/oursqlx/compat.o, file was built for unsupported file format which is not the architecture being linked (i386) ld: warning: ignoring file /usr/local/mysql-5.5.14-osx10.6-x86_64/lib/libmysqlclient.dylib, file was built for unsupported file format which is not the architecture being linked (i386) Successfully installed oursql Cleaning up... 
+8
python installation package macos
source share
4 answers

This completed the task:

 export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/" 
+6
source share

If you do not want to install full MySQL, you can compile oursql using mysql-connector-c.

Download mysql-connector-c, unzip and install:

 wget http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-6.0.2-osx10.5-x86-64bit.tar.gz/from/http://cdn.mysql.com/ tar -xvf mysql-connector-c-6-1.0.2-osx10.5-x86-64bit.tar cd mysql-connector-c-6.0.2-osx10.5-x86-64bit sudo cp bin/* /usr/local/bin/ sudo cp lib/* /usr/local/lib/ sudo cp -r include/* /usr/local/include/ 

Download and unzip oursql:

 wget --no-check-certificate https://launchpad.net/oursql/py3k/py3k-0.9.3/+download/oursql-0.9.3.zip unzip oursql-0.9.3.zip 

Compile oursql:

 cd oursql-0.9.3 sudo python setup.py build_ext 

This is confirmed to work with OSX 10.8.2, Xcode 4.5.2, and Python 3.2.3

0
source share

I came across this question while looking for a solution to install oursql on OSX 10.10.5. I previously installed mysql using brew brew install mysql . For those who want to install oursql on yosemite, here is what works for me:

1) Download the package manually. See the links here .

2) Open oursql/oursql-0.9.3.1/oursqlx/_exceptions.c in your favorite text editor

3) Commenting on the last "default" should look something like this:

  /*default: if (err >= ER_ERROR_FIRST && err <= ER_ERROR_LAST) return _oursqlx_ProgrammingError; else if (err > CR_MIN_ERROR && err < CR_MAX_ERROR) return _oursqlx_InterfaceError;*/ 

4) Now try to run the setup again:

 [sudo] python setup.py install 
0
source share

The best way to install the mysql server on mac os snow leopard is trying to install from the source file to make sure you compile mysql for the correct x86_64 architecture.

-one
source share

All Articles