4

Took me a days to get mysqldb working on Snow Leopard so this time round I did a completely clean install of the operating system and carefully followed the various instructions on installation to try and get my django development environment working.

brew install mysql 
sudo pip intall django
sudo pip install mysql-python

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
export PATH=/usr/local/mysql/bin:$PATH
sudo export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

Mysql and django working fine, but if I try to import MySQLdb or do a syncdb I get this error:

Python 2.7.2 (default, Oct 11 2012, 20:14:37) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/Library/Python/2.7/site-packages/_mysql.so, 2): Symbol not found: _mysql_affected_rows
  Referenced from: /Library/Python/2.7/site-packages/_mysql.so
  Expected in: flat namespace
 in /Library/Python/2.7/site-packages/_mysql.so
>>> 

Have been googling for a day now with no success and really need to get back to work! Any suggestions very welcome.

(also tried to install the mysql python-connector here http://dev.mysql.com/downloads/connector/python/ but there is no osx version and other instructions seem to imply you need the right version for your version of python no platform so I didn't pursue that further.)

Update

Having run brew doctor cleanly am getting these errors on trying the --universal option:

iMacs-iMac:~ phoebebr$ brew install -v  mysql --universal
==> Downloading http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.13.tar.gz/from/http://cdn.mysql.com/
Already downloaded: /Library/Caches/Homebrew/mysql-5.6.13.com
tar xf /Library/Caches/Homebrew/mysql-5.6.13.com
==> cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/mysql/5.6.13 -DMYSQL_DATADIR=/usr/local/var/mysql -DINSTALL_MANDIR=/usr/local/Cellar/mysql/5.6.13/share/man -DINSTALL_DOCDIR=/usr/local/Cellar/mysql/5.6.13/share/doc/mysql -DINSTALL_INFODIR=/usr/local/Cellar/mysql/5.6.13/share/info -DINSTALL_MYSQLSHAREDIR=share/mysql -DWITH_SSL=yes -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DSYSCONFDIR=/usr/local/etc -DWITH_UNIT_TESTS=OFF -DWITH_READLINE=yes -DCMAKE_OSX_ARCHITECTURES='i386;x86_64'
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/mysql/5.6.13 -DMYSQL_DATADIR=/usr/local/var/mysql -DINSTALL_MANDIR=/usr/local/Cellar/mysql/5.6.13/share/man -DINSTALL_DOCDIR=/usr/local/Cellar/mysql/5.6.13/share/doc/mysql -DINSTALL_INFODIR=/usr/local/Cellar/mysql/5.6.13/share/info -DINSTALL_MYSQLSHAREDIR=share/mysql -DWITH_SSL=yes -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DSYSCONFDIR=/usr/local/etc -DWITH_UNIT_TESTS=OFF -DWITH_READLINE=yes -DCMAKE_OSX_ARCHITECTURES='i386;x86_64'
-- Running cmake version 2.8.11.2
-- The C compiler identification is Clang 4.2.0
-- The CXX compiler identification is GNU 4.2.1
CMake Error at /usr/local/Cellar/cmake/2.8.11.2/share/cmake/Modules/Platform/Darwin.cmake:190 (message):
  CMAKE_OSX_DEPLOYMENT_TARGET is '10.8' but CMAKE_OSX_SYSROOT:

   ""

  is not set to a MacOSX SDK with a recognized version.  Either set
  CMAKE_OSX_SYSROOT to a valid SDK or set CMAKE_OSX_DEPLOYMENT_TARGET to
  empty.
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/2.8.11.2/share/cmake/Modules/CMakeSystemSpecificInformation.cmake:36 (include)
  CMakeLists.txt:99 (PROJECT)


-- Configuring incomplete, errors occurred!
==> Configuration
HOMEBREW_VERSION: 0.9.4
HEAD: b9b09cb1a620cd5ddafffc22d56a34e160bfc3f4
CPU: dual-core 64-bit penryn
OS X: 10.8.4-x86_64
Xcode: 4.6.3
CLT: 4.6.0.0.1.1365549073
X11: 2.7.4 => /opt/X11
==> ENV
CFLAGS: -Os -w -pipe
CXXFLAGS: -Os -w -pipe
LDFLAGS: -L/usr/local/lib
MAKEFLAGS: -j2
MACOSX_DEPLOYMENT_TARGET: 10.8
PKG_CONFIG_LIBDIR: /usr/local/lib/pkgconfig:/usr/local/Library/ENV/pkgconfig/10.8:/usr/lib/pkgconfig
OBJC: /usr/bin/clang
PATH: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/Library/Contributions/cmd
CPATH: /usr/local/include

Error: mysql did not build
Logs:       /Users/phoebebr/Library/Logs/Homebrew/mysql/CMakeCache.txt

Did find this related to cmake error but this is really getting beyond my technical ability! http://cmake.3232098.n2.nabble.com/OSX-deployment-target-confusion-for-2-8-10-td7582284.html Looking at the mysql site it's not obvious to me how to install universal directly.

UPdate 2

This page was useful: Error importing MySQLdb in Python 2.7.2 on Mac OSx 10.8.1

So installed mysql again without -- universal and checked the architecture of everything like this:

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

iMacs-iMac:mysql phoebebr$ which mysql
/usr/local/bin/mysql
iMacs-iMac:mysql phoebebr$ file /usr/local/bin/mysql
/usr/local/bin/mysql: Mach-O 64-bit executable x86_64

and still getting the same error.

iMacs-iMac:~ phoebebr$ python
Python 2.7.2 (default, Oct 11 2012, 20:14:37) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/Library/Python/2.7/site-packages/_mysql.so, 2): Symbol not found: _mysql_affected_rows
  Referenced from: /Library/Python/2.7/site-packages/_mysql.so
  Expected in: flat namespace
 in /Library/Python/2.7/site-packages/_mysql.so
>>> 
Community
  • 1
  • 1
PhoebeB
  • 8,434
  • 8
  • 57
  • 76
  • Back to only having sqlite on my mac then. Someone has suggested switching to Postgresql so might give that a go. – PhoebeB Aug 06 '13 at 10:53
  • Have you checked if your binaries are built for the right architecture? MacOSX keeps i386 and x86_64 binaries around, and sometimes in arbitrary combinations. Have you tried macports? I tried homebrew, but I was very disappointed about its inconsistency over time, so I switched back. – Sven Aug 06 '13 at 15:19
  • As this is a relatively new machine and a new install I could be confident everything was 64bit. Homebrew knows it's 64 bit, .bash_profile has export ARCHFLAGS="-arch x86_64" Is there anything else I should have done? – PhoebeB Aug 08 '13 at 08:48

3 Answers3

2

This is a known Bug -- the mysql-python package is built only for 64-bit at the moment.

Marcel Hauri
  • 432
  • 2
  • 6
0

Try installing mysql with the universal flag to avoid architecture binary mismatching. I would go through a complete uninstall of all related software and then clean installation of all related software.

brew install mysql --universal

The Debi
  • 157
  • 6
  • Reinstalling mysql with universal flag does not help. I even have MySql 32 bit installed on my Mac, same errors still occur. – Believe2014 Mar 25 '15 at 17:34
0

Might be a work around and not adress your issue, but if you have an old laptop/computer lying around, install a light linux distro on it and set that up as your sql database server.

Thats the way I set up my dev enviroments anyways so they reflect "real world" connectivity via the slight delay the network communication incurs.

Tschallacka
  • 27,901
  • 14
  • 88
  • 133