Mac MySQLdb模块安装,可算解决了
轉載:http://blog.csdn.net/janronehoo/article/details/25207825
叨叨
短評:這篇文章感覺是比較全面解決Mac MySQLdb模塊安裝問題的文章了,特別轉載一下
安裝過程主要是mysql_config not found錯誤,這個錯誤通常卡住很多初學者,以及安裝后出現的?image not found 錯誤
版本:Python 2.7.3
MySQL-python包中,因此無論下載還是在pip中search,都應該是搜尋MySQL-python。
流程:
下載MySQLdb
MySQL-python-1.2.4b4.tar,下載后解壓,然后在終端Terminal中執行以下命令:
new-host-3:~ iFantastic$ cd /Users/iFantastic/Downloads/MySQL-python-1.2.4b4 new-host-3:MySQL-python-1.2.4b4 iFantastic$ python setup.py install使用PIP安裝MySQLdb
new-host-3:~ iFantastic$ pip install MySQL-python無論是在線安裝還是下載安裝,此時你可能會遇到第一個錯誤提示:
EnvironmentError: mysql_config not found解決mysql_config not found錯誤
因此下載安裝時的解決辦法為:在MySQL-python的安裝包中找到site.cfg文件,打開它,找到以下內容:
# The path to mysql_config. # Only use this if mysql_config is not on your PATH, or you have some weird # setup that requires it. # mysql_config = /usr/local/bin/mysql_config將最后一句句首井號去掉,并修改為:
mysql_config = /usr/local/mysql/bin/mysql_config然后執行
$ python setup.py install一般說來,此時安裝可以完成,但仍有問題,下文會繼續闡述。
使用pip安裝時沒有辦法修改site.cfg文件,因此可以通過修改OS X的系統環境變量來解決找不到mysql_config的錯誤。
修改OS X環境變量:打開終端,在終端中使用vim打開“~/.bash_profile”,如果沒有安裝vim,那就顯示隱藏文件用文本編輯器打開,具體操作這里就不復述了。在.bash_profile中添加以下內容:
PATH="/usr/local/mysql/bin:${PATH}" export PATH export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/ export VERSIONER_PYTHON_PREFER_64_BIT=no export VERSIONER_PYTHON_PREFER_32_BIT=yes其中?VERSIONER_PYTHON_PREFER_64_BIT和VERSIONER_PYTHON_PREFER_64_BIT根據自己安裝的MySQL進行選擇。
$ sudo ln -s /usr/local/mysql/bin/* /usr/bin解決?Reason: image not found 錯誤
安裝完MySQL-python包后,讓我們import MySQLdb,此時出現一個錯誤,錯誤最后一行寫著 Reason: image not found。
解決方法是在終端執行:
$ sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib $ sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql錯誤:
clang: error:? clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
經網上查證:http://www.tuicool.com/articles/zI7Vzu貌似是mac os的Xcode從5.1起給編譯器規定對于未知參數傳入視為error我們需要使用ARCHFLAGS將該error降級為warning因此最后的安裝命令應該如下:
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future python setup.py build
參考:
http://www.cnblogs.com/macro-cheng/archive/2011/10/25/mysql-001.html
轉載于:https://www.cnblogs.com/wuzhi-seo/p/5500039.html
總結
以上是生活随笔為你收集整理的Mac MySQLdb模块安装,可算解决了的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NSDictionary NSArray
- 下一篇: 解决hibernate中的懒加载(延迟加