Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQLdb for Python 2.7 (Ubuntu)

After I installed MySQLdb by

sudo apt-get install python-mysqldb

I can import and use it when I use Python 2.6, but not 2.7. (ImportError: No module named MySQLdb)

I think that apt-get install MySQLdb in version 2.6, but I don't know how to make python 2.7 work with it. Please help me. Thanks a lot!

like image 219
iForests Avatar asked Apr 08 '12 10:04

iForests


People also ask

Does MySQLdb support Python 3?

MySQLdb module, a popular interface with MySQL is not compatible with Python 3.

What is Python MySQLdb package?

What is MYSQLdb? MySQLdb is an interface for connecting to a MySQL database server from Python. It implements the Python Database API v2. 0 and is built on top of the MySQL C API. Packages to Install mysql-connector-python mysql-python.

What is the difference between PyMySQL and MySQL?

PyMySQL and MySQLdb provide the same functionality - they are both database connectors. The difference is in the implementation where MySQLdb is a C extension and PyMySQL is pure Python. There are a few reasons to try PyMySQL: it might be easier to get running on some systems.


1 Answers

If you want system-wide installation for python2.7 you should use easy_install-2.7. Install setuptools (or distribute) for python 2.7, then type:

easy_install-2.7 mysql-python

Update:

Or just

sudo apt-get install python2.7-mysqldb

Notice without adding sudo you'd not be able to make the changes.

like image 160
Maksym Polshcha Avatar answered Oct 07 '22 16:10

Maksym Polshcha