一)准备
软件包: Python2.6.tar.gz、MySQL-python-1.2.3c1.tar.gz、setuptools-0.6c11.tar.gz。
二)安装
1)安装 python2.6,设置安装路径为/usr/local/python2.6。
[code="java"]# /usr/local/python2.6/bin/python
Python 2.6 (r26:66714, Nov 25 2011, 12:17:00)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb
>>> [/code]
2)源码编译MySQLdb模块
首先安装setuptool模块
[code="java"]# cd setuptools-0.6c11
# /usr/local/python2.6/bin/python setup.py build
...........................
# /usr/local/python2.6/bin/python setup.py install
[/code]
然后安装MySQLdb模块
解压MySQL-python-1.2.3c1.tar.gz ,进入解压目录,并修改site.cfg文件。
添加:mysql_config=your_mysql_dir/bin/mysql_config
[code="java"]# /usr/local/python2.6/bin/python setup.py install --prefix=/usr/local/python2.6/[/code]
但是导入MySQLdb模块还是出错,
做个软连接
[code="java"]# ln -s /usr/local/mysql/lib/mysql/libmysqlclient_r.so.16 /usr/lib/libmysqlclient_r.so.16
# /usr/local/python2.6/bin/python
Python 2.6 (r26:66714, Nov 25 2011, 12:17:00)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> [/code]
Python2.6的MySQLdb模块安装导入成功。
[b]python2.6下载地址:[/b]
[url]http://www.cnpythoner.com/pythondown/python2.6down.html[/url]
软件包: Python2.6.tar.gz、MySQL-python-1.2.3c1.tar.gz、setuptools-0.6c11.tar.gz。
二)安装
1)安装 python2.6,设置安装路径为/usr/local/python2.6。
[code="java"]# /usr/local/python2.6/bin/python
Python 2.6 (r26:66714, Nov 25 2011, 12:17:00)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb
>>> [/code]
2)源码编译MySQLdb模块
首先安装setuptool模块
[code="java"]# cd setuptools-0.6c11
# /usr/local/python2.6/bin/python setup.py build
...........................
# /usr/local/python2.6/bin/python setup.py install
[/code]
然后安装MySQLdb模块
解压MySQL-python-1.2.3c1.tar.gz ,进入解压目录,并修改site.cfg文件。
添加:mysql_config=your_mysql_dir/bin/mysql_config
[code="java"]# /usr/local/python2.6/bin/python setup.py install --prefix=/usr/local/python2.6/[/code]
但是导入MySQLdb模块还是出错,
>>> import MySQLdb
/usr/local/python2.6/lib/python2.6/site-packages/MySQL_python-1.2.3c1-py2.6-linux-i686.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/local/python2.6/lib/python2.6/site-packages/MySQL_python-1.2.3c1-py2.6-linux-i686.egg/_mysql.pyc, but /root/Desktop/MySQL-python-1.2.3c1 is being added to sys.path
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "MySQLdb/__init__.py", line 19, in <module>
import _mysql
File "build/bdist.linux-i686/egg/_mysql.py", line 7, in <module>
File "build/bdist.linux-i686/egg/_mysql.py", line 6, in __bootstrap__
ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
>>>
缺少libmysqlclient_r.so.16文件。
做个软连接
[code="java"]# ln -s /usr/local/mysql/lib/mysql/libmysqlclient_r.so.16 /usr/lib/libmysqlclient_r.so.16
# /usr/local/python2.6/bin/python
Python 2.6 (r26:66714, Nov 25 2011, 12:17:00)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> [/code]
Python2.6的MySQLdb模块安装导入成功。
[b]python2.6下载地址:[/b]
[url]http://www.cnpythoner.com/pythondown/python2.6down.html[/url]