http://sourceforge.net/projects/mysql-python/files/mysql-python-test/1.2.3b1/MySQL-python-1.2.3b1.tar.gz/download
tar -zxf MySQL-python-1.2.3b1.tar.gz
cd MySQL-python-1.2.3b1
python setup.py build
==>ImportError: No module named setuptools
2.下载setuptools
http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c8.tar.gz
tar -zxf setuptools-0.6c8.tar.gz
cd setuptools-0.6c8
python setup.py build
python setup.py install
3.回到MySQL-python-1.2.3b目录
cd MySQL-python-1.2.3b1
在运行时python setup.py build && python setup.py install没有如下错误:
有类似错误,处理方式如下:
python setup.py build
#若,报错:mysql_config not found
找出mysql 安装目录如:/opt/mysql/
vim MySQL-python-1.2.3b1/setup_posix.py
'''行26''' mysql_config.path = "mysql_config"
改成如下:
'''行27''' mysql_config.path = "/opt/mysql/bin/mysql_config"
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
根据最后提示,应该是找不着一个交libmysqlclient.so.18的文件,于是到mysql安装目录里找到这个文件并且做一个软连接到/usr/lib
如果找不到 可以执行如下命令,找到MySQL安装目录的该文件:
find / -name libmysqlclient.so.18
然后创建软连接 本地so.18路径 > /usr/lib/libmysqlclient.so.18
32位:
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
64位:
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
>>>import MySQLdb
/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3b1-py2.7-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3b1-py2.7-linux-x86_64.egg/_mysql.pyc, but /data/tools/MySQL-python-1.2.3b1 is being added to sys.path
原因是,install后MySQLdb模块已经被放到python的site-pachages目录中;但我在当前目录也存在相同的模块,所以可能会重复导入。只要切换到其他目录运行就可以了。
参考:
http://blog.csdn.net/ys1109/article/details/17357639
http://www.jb51.net/article/54120.htm
http://blog.csdn.net/jiang1013nan/article/details/6270791