解決python2安裝MySQL-python模組報錯

來源:互聯網
上載者:User

標籤:AC   macos   site   cos   blog   set   http   bash   port   

今天電腦重裝系統,所有軟體都重裝一遍,MySQLdb模組一直裝不好,糾結了好久,終於解決,方法分享給大家。 MySQLdb模組安裝:

1、下載MySQL-pyhon模組,網站為:https://pypi.python.org/pypi/MySQL-python/

2、解壓,進入目錄,修改site.cfg檔案13行,取消注釋,將原路徑mysql_config = /usr/local/bin/mysql_config,改為新的mysql_config = /usr/local/mysql/bin/mysql_config(mysql_config路徑,不知道的可以使用whereis命令查詢路徑),儲存;

3、修改setup_posix.py 檔案第27行,將原路徑mysql_config.path = "mysql_config"改為mysql_config.path = "/usr/local/mysql/bin/mysql_config",儲存;

4、將export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/(路徑為mysql安裝路徑,寫完自己mysql安裝路徑即可)加入目前使用者家目錄下的.bash_profile或者/etc/profile檔案中,.bash_profile是當前登入使用者的環境變數,/etc/profile是系統內容變數,然後執行命令 soure .bash_profile或者source /etc/profile;

5、安裝,執行python setup.py build 和python setup.py install ;

6、驗證,進入python互動式命令列,import MySQLdb,不報錯即安裝成功;

7、該解決方案適用於Macosx、Centos、Redhat、Ubuntu、Windows。

解決python2安裝MySQL-python模組報錯

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.