无法在OS X 10.10 Yosemite上安装Python-MySQL

13
我无法安装Python-MySQL,我已经尝试使用easy_install、pip和源码。但是我总是收到同样的错误。这就是我收到的内容:

我无法安装Python-MySQL,我已经尝试使用easy_install、pip和源码。但是我总是收到同样的错误。这就是我收到的内容:

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

作为一个小事实,MySQL-python似乎被唯一的项目所有者放弃了,并且不支持Python 3(尽管有一些Py3兼容的分支)。使用由Oracle支持的mysql-connector-python包(适用于Python 2和3)是一个选择吗? - Nick T
3个回答

15
我已经如下解决了这个问题:
  1. 安装了OSX命令行工具之后,安装MySQL-python。

    $ xcode-select --install

    $ sudo pip install MySQL-python

    (发出了三条警告信息,但是,“MySQL-python安装成功”…)

  2. 从Python解释器中的“import MySQLdb”错误(“image not found”错误)以以下方式解决:

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

我的环境是“OSX Yosemite,mysql 5.6.21,Python 2.7.8”。

祝好运。


1
这个方法解决了我遇到的令人沮丧的“import MySQLdb”错误。 - pythonjsgeo
1
在OSX Yosemite上将MySQL从5.6.26升级到5.7.10之后,Python 2.7.11 sudo ln -s /usr/local/Cellar/mysql/5.6.26/lib/libmysqlclient.18.dylib /usr/local/lib/ - ajsmith007

2
建议您使用pip而不是easy-install,因为它是更高级的解决方案。有关原因,请参见此处
由于您还遇到了XCode错误,可能没有安装OSX命令行工具。编译MySQL-python需要这些工具。您可以在登录后从Apple下载并安装它们。
如果您仍然遇到错误,请通过homebrew安装mysql-clientbrew install mysql --client-only

大家好,有人解决了这个问题吗?我仍然遇到这个错误:"嗨,大家好,有人已经解决了这个问题吗?我仍然得到" - alfdev

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接