Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MySQLdb module with Pypy compiler

I'm trying Pypy compiler to see if I can speed up my code. Nevertheless, I'm having troubles with MySQLdb module, which Pypy is unable to find.

I have read that MySQLdb 1.2.4 should work fine with Pypy, so I upgraded the module, and I tested that it is the right version with CPython compiler:

import MySQLdb
MySQLdb.__version__
>> '1.2.4'

But when using Pypy, I'm getting:

Python 2.7.2 (1.9+dfsg-1, Jun 19 2012, 23:23:45)
[PyPy 1.9.0 with GCC 4.7.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``-FIRST they ignore you, then they
laugh at you, then they fight you, then you win.-''
>>>> import MySQLdb
Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: No module named MySQLdb

Any help? I'm running over Ubuntu 13.04 and using Pypy which came into the Canonical repositories.

like image 930
Roman Rdgz Avatar asked Jun 24 '13 09:06

Roman Rdgz


People also ask

Which is better PyMySQL or MySQL connector?

According to the maintainer of both mysqlclient and PyMySQL , you should use PyMySQL if: You can't use libmysqlclient for some reason. You want to use monkeypatched socket of gevent or eventlet. You wan't to hack mysql protocol.

What is MySQLdb module?

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.

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

MySQLdb is mostly written in C which pypy can't use directly. You'd need to patch and recompile it.

The easier solution would be to use a pure python mysql connector library, like pymysql or mysql-connector-python

pymysql can even be used as dropin replacement for MySQLdb, all you need to do add:

import pymysql
pymysql.install_as_MySQLdb()

or put this in a module MySQLdb.py, after that code which imports MySQLdb should work normally.

like image 184
mata Avatar answered Oct 25 '22 20:10

mata