如果你伺服器環境允許yum,安裝MySQL-python模塊就很簡單了。 如果直接安裝不行,先 安裝MySQL-devel後正常運行 yum install mysql-devel yum install MySQL-python -y 1 yum install MySQL-python -y 當 ...
如果你伺服器環境允許yum,安裝MySQL-python模塊就很簡單了。
如果直接安裝不行,先
安裝MySQL-devel後正常運行
yum install mysql-devel
1 | yum install MySQL-python -y |
當然也可以源碼安裝該模塊
首先安裝 setuptools,下載源代碼包:
1 2 3 4 5 | wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz 解壓後 python setup.py build python setup.py install |
然後安裝一些擴展庫
1 | yum -y install rpm-build gcc-c++ mysql-devel python-devel |
最後安裝MySQL-python
1 2 3 4 5 6 7 8 | 下載源代碼包: wget http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz 解壓進入安裝目錄。 編輯 site.cfg ,把 mysql_config 那一行取消註釋,並改為: mysql_config = /usr/lib64/mysql/mysql_config (根據自己mysql安裝位置定義) python setup.py build python setup.py install |
測試安裝
1 2 3 4 5 6 7 | [root@woyoo:/tmp/MySQL-python-1.2.3]# python Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb /usr/lib64/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib64/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-x86_64.egg/_mysql.pyc, but /tmp/MySQL-python-1.2.3 is being added to sys.path >>> |
報出一大堆警告信息,解決辦法:刪除MySQL-python源目錄,再測試一下: