系统:Ubuntu
安装:
milo@nf:~$ sudo apt-get install python-dev milo@nf:~$ sudo apt-get install libmysqld-dev
milo@nf:~$ python Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named MySQLdb >>> exit() milo@nf:~$ sudo apt-get install python-mysqldb milo@nf:~$ python Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb >>>
可以正常使用了。
但是进入virtuanlenv环境下依旧报错
milo@nf:~/.virtualenvs/web01$ workon web01 (web01)milo@nf:~/.virtualenvs/web01$ python Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named MySQLdb
在virtualenv环境中安装:
(web01)milo@nf:~/.virtualenvs/web01$ pip install MySQL-python (web01)milo@nf:~/.virtualenvs/web01$ python Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb >>>