`
sls0919
  • 浏览: 123115 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ubuntu python2.7安装mysql-python

阅读更多

 

Python连接mysql

 

>>> import MySQLdb
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    import MySQLdb
ImportError: No module named MySQLdb
>>> 

 

 

 解决方法:

1. sudo easy_install mysql-python

若报错,提示找不到setuptools

需要先安装setuptools

2. sudo apt-get install  python-setuptools

继续执行 1 

若提示EnvironmentError: mysql_config not found(即找不到mysql_config)原因没有安装libmysqlclient

3. 在/etc/apt/sources.list 中加入 deb http://security.ubuntu.com/ubuntu maverick-security main     

4.  sudo apt-get install libmysqlclient-dev

 仍然失败,提示找不到Python.h

5. 在/etc/apt/sources.list 中加入 deb http://ubuntu.mirror.cambrium.nl/ubuntu/ maverick main

 6. 执行 sudo apt-get install python-dev

重新执行1 ,mysql-python安装成功

 

还有一种mac下安装提示mysql_config找不到

需要:ln -s /usr/local/mysql/bin/mysql_config /usr/local/bin/mysql_config

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics