13

I can't install Python-MySQL, I already tried with easy_install, pip and sources.. And I always get the same error. This is what I get:

Matts-MacBook:Python matt$ sudo easy_install MySQL-python
Searching for MySQL-python
Reading https://pypi.python.org/simple/MySQL-python/
Best match: MySQL-python 1.2.5
Downloading https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-           1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c
Processing MySQL-python-1.2.5.zip
Writing /tmp/easy_install-i14rIs/MySQL-python-1.2.5/setup.cfg
Running MySQL-python-1.2.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-i14rIs/MySQL-    python-1.2.5/egg-dist-tmp-mG9d4K
clang: warning: -framework CrashReporterSupport: 'linker' input unused
In file included from _mysql.c:44:
/usr/local/mysql/include/my_config.h:349:11: warning: 'SIZEOF_SIZE_T' macro redefined
#define SIZEOF_SIZE_T  SIZEOF_LONG
      ^
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pymacconfig.h:56:17: note: 
  previous definition is here
#        define SIZEOF_SIZE_T           4
^In file included from _mysql.c:44:
/usr/local/mysql/include/my_config.h:443:9: warning: 'HAVE_WCSCOLL' macro redefined
#define HAVE_WCSCOLL
    ^
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pyconfig.h:912:9: note: 
  previous definition is here
#define HAVE_WCSCOLL 1
    ^
_mysql.c:1589:10: warning: comparison of unsigned expression < 0 is always false
  [-Wtautological-compare]
    if (how < 0 || how >= sizeof(row_converters)) {
        ~~~ ^ ~
3 warnings generated.
ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.Internal.sdk/System/Library/PrivateFrameworks'
ld: framework not found CrashReporterSupport
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: Setup script exited with error: command 'cc' failed with exit status 1
Matt
  • 133
  • 1
  • 1
  • 6
  • As a minor point of fact, MySQL-python seems to be abandoned by the sole project owner and doesn't support Python 3 (though there are Py3-compatible forks out there). Is using the Oracle-supported [mysql-connector-python](https://pypi.python.org/pypi/mysql-connector-python) package (works with Python 2 and 3) an option? – Nick T Oct 18 '14 at 19:09

3 Answers3

15

I've solved the problem as follows:

  1. After installing the OSX command line tools, to install the MySQL-python.

    $ xcode-select --install

    $ sudo pip install MySQL-python

    (Three warning message is issued, but, "Successfully installed MySQL-python" ...)

  2. "import MySQLdb" error from the Python interpreter("image not found" error) has been solved in the following way:

    $ sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/

My environment, "OSX Yosemite, mysql 5.6.21, Python 2.7.8".

Good luck.

cloudera
  • 166
  • 1
  • 5
  • 1
    This fixed the frustrating "import MySQLdb" error for me. – pythonjsgeo Jan 14 '15 at 03:55
  • 1
    After upgrading MySQL to 5.7.10 from 5.6.26 on OSX Yosemite, Python 2.7.11 `sudo ln -s /usr/local/Cellar/mysql/5.6.26/lib/libmysqlclient.18.dylib /usr/local/lib/` – ajsmith007 Dec 16 '15 at 18:39
2

It's recommended to use pip instead of easy-install, as it's the more advanced solution. See here for reasons.

Since you also get an XCode error you probably don't have the OSX command line tools installed. They are required for compiling MySQL-python. You can download them from Apple after logging in.

If you should still run into an error, install mysql-client via homebrew. brew install mysql --client-only

Community
  • 1
  • 1
Manu
  • 3,212
  • 1
  • 16
  • 14
  • Hi guys, anyone had solved this issue? i still gets this error: "Hy guys, anyone has solved this issue? i still got" – alfdev Mar 07 '16 at 19:12
0

Install mysql via homebrew first.For homebrew installation refer this link http://coolestguidesontheplanet.com/installing-homebrew-os-x-yosemite-10-10-package-manager-unix-apps/ then

pip uninstall MySQL-python
brew install mysql
pip install MySQL-python
Geek
  • 1,369
  • 1
  • 14
  • 25