昨天在安装python的 MySQLdb模块时遇到几个问题,写出来和大家分享下。
1.下载MySQLdb模块
wget
解压:tar -zxvf MySQL-python-1.2.3c1.tar.gz
安装:python setup.py install
出错(1):ImportError: No module named setuptools
错误原因:没有安装setuptools
解决办法: 到这里下载
wget -q
python ez_setup.py
出错(2):pymemcompat.h:10:20: error: Python.h: No such file or directory
出错原因:没有安装python-devel
解决办法:yum install python-devel
现在运行python setup.py install 就ok了
可以试试运行python
python
>>>import MySQLdb(一定要注意大小写)
/usr/lib64/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib64/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-x86_64.egg/_mysql.pyc, but /home/younema/MySQL-python-1.2.3c1 is being added to sys.path
>>>
出错原因:以为安装目录里存在sys.path
解决办法:退出当前安装目录,再运行python解释器,import MySQLdb 就ok了
阅读(7382) | 评论(2) | 转发(0) |