1、下载,解压python-mysql
2、运行python setup.py install
3、Error1: 报错mysql_config not found
首先查找mysql_config的位置,使用find / -name mysql_config
其次、修改setup_posix.py文件
mysql_config.path = "mysql_config" 改为
mysql_config.path = "/usr/local/mysql/bin/mysql_config" # 这里的路径是自己系统的mysql_config的路径
4、Error2:
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 directory In 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 input error: command 'gcc' failed with exit status 1
需要安装python-devel
yum install python-devel
5、Error3:在运行,import MySQLdb 时报ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
将安装的mysql的lib中的libmysqlclient.so.18做个然连接就ok了,
>>> find / -name libmysqlclient.so.18 >>> ln -s /usr/local/server/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18 >>> ldconfig # 立即生效
6、Error4:在运行,import MySQLdb 时报ImportError: libssl.so.1.0.0: cannot open shared object file: No such file or directory
find / -name libssl.so.1.0.0 ln -s /opt/lamp/lib/libssl.so.1.0.0 /usr/lib ldconfig
///////////////////////// 分割线 //////////////////////////////
(2014-03-08更新,开源中国社区)
7、使用一种完美解决python-mysqldb安装的方式:(不要问,为什么,反正运行了,就可以避免很多错误)
yum install gcc python-devel mysql-devel -y
上面运行过后,会解决一些MySQLdb使用到的一些依赖;
8、如果你是在Centos下安装的MySQLdb,安装完成后,在/usr/lib64/python2.6/site-packages/生成相应的egg文件,我使用的是1.2.5;可能在使用apache部署投入生产环境使用的时候,会有
kages/setuptools-2.2-py2.6.egg/pkg_resources.py:991: UserWarning: /root/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
那就需要在apache连接python模块时指定PYTHON_EGG_CACHE,我使用的是{{ 项目名称 }}/wsgi.py的方式做连接,在wsgi.py里添加:
os.environ['PYTHON_EGG_CACHE'] = '/tmp/.python-eggs'
持续更新。。。
郑重声明,未经本人允许,不得任何形式的转载和copy,请尊重原版;http://my.oschina.net/shniu/admin/edit-blog?blog=205379