【问题标题】:How to install MySQLdb on Mountain Lion如何在 Mountain Lion 上安装 MySQLdb
【发布时间】:2012-08-02 22:59:10
【问题描述】:

我是 Python 新手,在构建 MySQLdb 时遇到了麻烦,试图让 Google AppEngine SDK 运行。我刚刚从 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

【问题讨论】:

    标签: python mysql installation


    【解决方案1】:

    系统好像是在抱怨找不到clang,包含在XcodeCommand Line Tools中。你也安装了这个工具吗?

    可以通过安装

    • 打开Xcode
    • 偏好 (Command + ,)
    • ComponentsDownload 标签下

    【讨论】:

      【解决方案2】:

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

      我假设你已经安装了 XCode,它是命令行工具、Python 和 MySQL。

      1. 安装画中画:

        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
      【解决方案3】:

      看来这不是您需要做的唯一事情,我检查了无法识别的 cc 编译器,并且没有指向正确的文件,谷歌搜索我发现我需要更改一些文件才能找到它在构建之前,并不止于此,现在它的识别不会对 DYDL 库收费......开始使用 python 真的很难找到真正的答案。

      【讨论】:

        【解决方案4】:

        我终于在自述文件中找到了要编辑 site.cfg 并将 mysql_config 的位置放在那里。

        【讨论】:

          猜你喜欢
          • 2012-10-11
          • 1970-01-01
          • 2013-04-06
          • 2012-08-22
          • 2013-11-05
          • 2013-03-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多