簡體   English   中英

如何在Mountain Lion上安裝MySQLdb

[英]How to install MySQLdb on Mountain Lion

我是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

似乎系統抱怨無法找到clang ,它包含在Xcode Command Line Tools中。 你也安裝了這個工具嗎?

可以通過安裝

  • 打開Xcode
  • 偏好( Command + ,
  • Download選項卡下的Components

如果有人對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" 

它對我來說就像一個魅力。 我希望它有所幫助。

這似乎不是你需要做的唯一的事情,我檢查一下無法識別的cc編譯器,並且沒有指向正確的文件,谷歌搜索我發現我需要更改一些文件才能在構建之前找到它,並不止於此,現在它的識別並沒有給DYDL圖書館收費......為了開始使用python,真的很難找到真正的答案。

我終於發現它在自述文件中說編輯site.cfg並將mysql_config的位置放在那里。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM