Using MySQLdb Module Using Pypy Compiler

I am trying to use the pypy compiler to find out if I can speed up my code. However, I am having problems with the MySQLdb module, which Pypy cannot find.

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

import MySQLdb MySQLdb.__version__ >> '1.2.4' 

But when using Pypy I get:

 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 am running Ubuntu 13.04 and using Pypy, which ended up in canonical repositories.

+6
source share
1 answer

MySQLdb is mainly written in C, which pypy cannot use directly. You need to plan and recompile it.

A simpler solution would be to use a clean mysql connector library with pure python like pymysql or mysql-connector-python

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

 import pymysql pymysql.install_as_MySQLdb() 

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

+12
source

Source: https://habr.com/ru/post/947978/


All Articles