2、解壓
3、安裝
$ python setup.py build
$ python setup.py install
不過在python setup.py build時報錯:
ImportError: No module named setuptools
解決辦法:ubuntu下安裝python-setuptools:
sudo apt-get install python-setuptools
python-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-dev
libmysqld-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-dev
python-dev : header files and a static library for Python (default)
然後就按照README裏的:
$ python setup.py build
$ sudo python setup.py install
測試:
>>>import MySQLdb
沒有報錯即可。