【问题标题】:Can't install Python-MySQL on OS X 10.10 Yosemite无法在 OS X 10.10 Yosemite 上安装 Python-MySQL
【发布时间】:2014-09-11 17:58:05
【问题描述】:

我无法安装 Python-MySQL,我已经尝试过使用 easy_install、pip 和 sources.. 而且我总是遇到同样的错误。这是我得到的:

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)?

标签: python mysql macos osx-yosemite


【解决方案1】:

我已经解决了如下问题:

  1. 安装OSX command line tools后,安装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”。

祝你好运。

【讨论】:

  • 这为我解决了令人沮丧的“导入 MySQLdb”错误。
  • 在 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/
【解决方案2】:

建议使用pip 而不是easy-install,因为它是更高级的解决方案。原因见here

由于您还收到 XCode 错误,您可能没有安装 OSX 命令行工具。它们是编译MySQL-python 所必需的。登录后可以从Apple下载。

如果您仍然遇到错误,请通过homebrew 安装mysql-clientbrew install mysql --client-only

【讨论】:

  • 大家好,有人解决了这个问题吗?我仍然收到此错误:“大家好,有人解决了这个问题吗?我仍然收到了”
【解决方案3】:

首先通过自制软件安装mysql。自制软件安装参考这个链接 http://coolestguidesontheplanet.com/installing-homebrew-os-x-yosemite-10-10-package-manager-unix-apps/ 那么

pip uninstall MySQL-python
brew install mysql
pip install MySQL-python

【讨论】: