CentOs 下安装python的MySQLdb

来源:互联网 发布:英魂之刃英雄数据库 编辑:程序博客网 时间:2024/06/05 20:35

进入python的命令行,输入 import MySQLdb 如果没有报错,证明此模块已经安装,

wget -O python-1.2.3c1.tar.gz  http://cdnetworks-kr-1.dl.sourceforge.net/project/mysql-python/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz

出现报错:ImportError: No module named setuptools

安装setuptools

wget -O setuptools-0.6c8.tar.gz  http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c8.tar.gz

cd setuptools-0.6c8

python setup.py build

sudo python setup.py install

报错:mysql_config not found

使用whereis mysql命令找到mysql安装目录,假设mysql安装在/usr/local/mysql

回到MySQLdb源码目录.

vi setup_posix.py 或 vim setup_posix.py打开配置文件。此时,找到mysql_config.path 一行,把路径前面加上第9步的mysql安装路径,bin目录。即mysql_config.path = "/usr/local/mysql/bin/mysql_config"

In file included from _mysql.c:29:pymemcompat.h:10:20: error: Python.h: No such file or directory_mysql.c:30:26: error: structmember.h: No such file or directoryIn file included from /usr/include/mysql/mysql.h:44,from _mysql.c:40:..._mysql.c:2808: warning: return type defaults to 'int'_mysql.c: In function 'DL_EXPORT':_mysql.c:2808: error: expected declaration specifiers before 'init_mysql'_mysql.c:2886: error: expected '{' at end of inputerror: command 'gcc' failed with exit status 1
需要安装install python-dev package:

yum install python-devel

安装完成后,import MySQLdb时:>>> import MySQLdbTraceback (most recent call last):File "", line 1, in File "MySQLdb/__init__.py", line 19, in import _mysqlFile "build/bdist.linux-i686/egg/_mysql.py", line 7, in 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

vim /etc/ld.so.conf

加入:libmysqlclient_r.so.16所在目录

ldconfig -v

ok了


原创粉丝点击