Python 安装MySQLdb模块问题总结

centos6.6下安装MySQLdb时出现“error: command 'gcc' failed with exit status 1”

1. 问题描述

在MySQL-python-1.2.3源码包根目录下执行安装命令:

# python setup.py install

出现以下信息:

error: command ‘gcc’ failed with exit status 1
2. 解决方法

在安装MySQLdb前安装以下依赖库:

# yum install python-devel mysql-devel zlib-devel openssl-devel

安装完以上依赖库后, 再在MySQL-python-1.2.3源码包根目录下执行以下安装命令即可:

# python setup.py install

如下信息表示MySQLdb安装成功:

Installed /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg
Processing dependencies for MySQL-python==1.2.3
Finished processing dependencies for MySQL-python==1.2.3
接着还要重新编译安装Python-2.7.9, 在Python-2.7.9源码包根目录下执行以下命令:

# ./configure && make && make install

3. 检测模块MySQLdb是否可正常使用

在终端执行以下命令:

# python
Python 2.7.9 (default, Feb  7 2015, 17:28:17)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>
 


ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory

问题:
>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.linux-x86_64/egg/MySQLdb/__init__.py", line 19, in <module>
  File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in <module>
  File "build/bdist.linux-x86_64/egg/_mysql.py", line 6, in __bootstrap__
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory

解决方法:
1.查看libmysqlclient.so.18的路径
# find / -name libmysqlclient.so.18
2.链接
# ln -s /mysql/base/lib/libmysqlclient.so.18     /usr/lib64/libmysqlclient.so.18
我这里是64位的,如果是32位的链接到/usr/lib




分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS