Ubuntu 9.04下安装MySQLdb 1.2.5

来源:互联网 发布:java jar软件下载 编辑:程序博客网 时间:2024/06/05 20:39

简介

在Ubuntu 9.04系统下,Python 2.6.2开发环境下,安装配置MySQLdb 1.2.5遇到一些问题,在这里简单总结一下

问题1: mysql_config: not found

下载了MySQLdb-1.2.5的源码解压,运行"sudo python setup.py install"发现了下面的错误信息
sh: mysql_config: not foundTraceback (most recent call last):  File "setup.py", line 17, in <module>    metadata, options = get_config()  File "/home/infinera/MySQLdb1-MySQLdb-1.2.5/setup_posix.py", line 43, in get_config    libs = mysql_config("libs_r")  File "/home/infinera/MySQLdb1-MySQLdb-1.2.5/setup_posix.py", line 25, in mysql_config    raise EnvironmentError("%s not found" % (mysql_config.path,))EnvironmentError: mysql_config not found
提示shell命令mysql_config没有找到,研究了setup_posix.py源码后,发现其需要通过mysql_config命令来查看配置信息,查找了系统确实没有相关命令。
研究发现mysql_config是libmysqlclient-dev包提供命令,需要安装相关的软件包,安装命令
sudo apt-get install libmysqlclient-dev

问题2:_mysql.c编译错误

问题1解决后,再重新安装时,发现编译过程中出现了下面的错误:
_mysql.c:3010: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_mysql.c:3058: warning: return type defaults to ‘int’_mysql.c: In function ‘DL_EXPORT’:_mysql.c:3058: error: expected declaration specifiers before ‘init_mysql’_mysql.c:3166: error: expected ‘{’ at end of inputerror: command 'gcc' failed with exit status 1
最终研究发现,没有安装python-dev包,安装命令
sudo apt-get install python-dev

总结

MySQLdb依赖python-dev和libmysqlclient-dev包,需要进行安装。

参考资料

1. virtualenv pip install mysql-python fails
2. Installing MySQL-python

0 0
原创粉丝点击