mac下安裝mysql-python

來源:互聯網
上載者:User

mac下安裝mysql-python,下載源碼在: http://sourceforge.net/projects/mysql-python/files/?source=navbar

解壓後執行 python setup.py build

報出錯誤為:

sh: mysql_config: command not found
Traceback (most recent call last):
  File "setup.py", line 18, in <module>
    metadata, options = get_config()
  File "/Users/dongquan/Downloads/MySQL-python-1.2.4b4/setup_posix.py", line 43, in get_config
    libs = mysql_config("libs_r")
  File "/Users/dongquan/Downloads/MySQL-python-1.2.4b4/setup_posix.py", line 25, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found

解決的辦法是,修改 安裝目錄下,site.cfg, 

約12行附近,增加 mysql_config = /usr/local/mysql/bin/mysql_config 

用來指定mysql的安裝位置

繼續執行 python setup.py build,

然後安裝,執行sudo python setup.py install,安裝完畢

在命令列中測試import MySQLdb,會曝出錯誤
Traceback (most recent call last):

  File "<stdin>", line 1, in <module>
  File "MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so
  Reason: image not found

解決方案: 建立libmysqlclient.18.dylib的“捷徑”
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/

再次執行import MySQLdb,就沒有錯誤了

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.