如何在Mountain Lion上安装MySQLdb

10

我是Python新手,在尝试启动Google AppEngine SDK时遇到了构建MySQLdb的问题。我刚从Snow Leopard升级到Mountain Lion,并安装了最新的XCode(4.4)。

我已经下载了http://sourceforge.net/projects/mysql-python/

python setup.py build 

我在终端中得到了以下输出

running build
running build_py
creating build
creating build/lib.macosx-10.8-intel-2.7
copying _mysql_exceptions.py -> build/lib.macosx-10.8-intel-2.7
creating build/lib.macosx-10.8-intel-2.7/MySQLdb
copying MySQLdb/__init__.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb
copying MySQLdb/converters.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb
copying MySQLdb/connections.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb
copying MySQLdb/cursors.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb
copying MySQLdb/release.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb
copying MySQLdb/times.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb
creating build/lib.macosx-10.8-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.8-intel-    2.7/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.macosx-10.8-intel-2.7
clang -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 -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/local/mysql/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.8-intel-2.7/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch x86_64
unable to execute clang: No such file or directory
error: command 'clang' failed with exit status 1

以下两个目录都存在,我不知道如何解决clang无法执行的问题...

/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
/usr/local/mysql/include
4个回答

19

看起来系统提示无法找到 clang,这是包含在 XcodeCommand Line Tools 中的。您是否也安装了该工具?

可通过以下方式安装:

  • 打开 Xcode
  • 选择偏好设置(Command+,
  • 在“下载”选项卡下选择 Components

1

如果有人对 Mac OS X 10.8 快速简便的方法感兴趣:

我假设您已经安装了 XCode、命令行工具、Python 和 MySQL。

  1. 安装PIP:

    sudo easy_install pip
    
  2. 编辑 ~/.profile:

    nano ~/.profile
    

    复制并粘贴以下两行内容

    export PATH=/usr/local/mysql/bin:$PATH
    export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
    

    保存并退出。之后执行以下命令

    source  ~/.profile
    
  3. 安装MySQLdb

    sudo pip install MySQL-python
    

    为了测试是否一切正常,只需尝试运行

    python -c "import MySQLdb"
    
它对我来说像魔法一样有效。希望它能帮到你。

这对我有用,除了我使用的是.bash_profile而不是.profile。 - mlbright

0

我终于找到了ReadMe中说要编辑site.cfg并在其中放置mysql_config位置的内容。


0

看起来这不是你需要做的唯一事情,我检查了一下cc编译器,发现它无法识别,并且没有指向正确的文件。通过谷歌搜索,我发现在构建之前需要更改一些文件才能找到它,但问题并没有止步于此,现在即使它被识别了,也无法加载DYDL库...真的很难找到一个真正的答案来开始使用Python。


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