Python的MySQLdb模組安裝

來源:互聯網
上載者:User

標籤:

在配置Django時,選擇的是mysql資料庫,要安裝MySQLdb模組,不過安裝過程中,遇到了很多errors,記錄一下。 系統:ubuntu 11.10mysql:直接apt-get安裝的,version:5.1.62 到官方下載MySQL for Python然後解壓,開啟README:裡面有安裝過程: $ tar xfz MySQL-python-1.2.1.tar.gz $ cd MySQL-python-1.2.1 $ # edit site.cfg if necessary $ python setup.py build $ sudo python setup.py install # or su first 不過在python setup.py build時報錯:ImportError: No module named setuptoolsubuntu下安裝:sudo apt-get install python-setuptoolspython-setuptools : Python Distutils Enhancements (setuptools compatibility) 然後再次python setup.py build,又報錯:EnvironmentError: mysql_config not found因為mysql_config是屬於MySQL開發用的檔案,而使用apt-get安裝的MySQL是沒有這個檔案的,於是在包安裝器裡面尋找sudo apt-get install libmysqld-devlibmysqld-dev : MySQL embedded database development files 再次運行python setup.py build,報錯:building ‘_mysql’ extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,’final’,0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-i686-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX In file included from _mysql.c:29:0: pymemcompat.h:10:20: fatal error: Python.h: No such file or directory解決方案,sudo apt-get install python-devpython-dev : header files and a static library for Python (default) 然後就按照README裡的: $ python setup.py build $ sudo python setup.py install測試:>>>import MySQLdb沒有報錯即可。 參考:http://blog.csdn.net/guzicheng/article/details/5884106http://be-evil.org/post-185.htmlhttp://hi.baidu.com/hevensun/blog/item/3b6e313fe8515df154e7238f.htmlhttp://stackoverflow.com/questions/1449130/how-to-install-mysqldb-package-importerror-no-module-named-setuptoolshttp://www.cnblogs.com/objdump/archive/2011/11/03/mysql_python_install_error.htmlsrc:http://www.cnblogs.com/rollenholt/archive/2012/05/07/2487137.html

Python的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.