Using MySQLdb 1.2.2 with python 2.6.1

When importing MySQLdb 1.2.2 into python 2.6.1 an error is reported:

Python 2.6.1 (r261:67515, Dec  7 2008, 08:27:41)
[GCC 4.3.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
>>> import MySQLdb
/usr/lib/python2.6/site-packages/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet

This is because the sets module is not built-in into the core distribution of python.

To get rid of this error and use the more efficient built-in set
type, do the following in the __init__.py file that was reported:

* comment line 34:

When importing MySQLdb 1.2.2 into python 2.6.1 an error is reported:

Python 2.6.1 (r261:67515, Dec  7 2008, 08:27:41)
[GCC 4.3.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
>>> import MySQLdb
/usr/lib/python2.6/site-packages/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet

This is because the sets module is not built-in into the core distribution of python.

To get rid of this error and use the more efficient built-in set
type, do the following in the __init__.py file that was reported:

* comment line 34: from sets import ImmutableSet

* add after that line: ImmutableSet = frozenset

* comment line 41 in the original file: from sets import BaseSet

* add after that line: BaseSet = set

Like this the built-in types will be used anytime a BaseSet or an ImmutableSet is referenced.

Now everything works fine:

Python 2.6.1 (r261:67515, Dec  7 2008, 08:27:41)
[GCC 4.3.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import MySQLdb
>>> MySQLdb.version_info
(1, 2, 2, ‘final’, 0)
>>>

Tags: , ,

8 Responses to “Using MySQLdb 1.2.2 with python 2.6.1”

  1. pedromagnus Says:

    Good post. The deprecated message was disturbing me :P
    But now appears another warning (derivating from the change on the __init__.py file):

    /var/lib/python-support/python2.6/MySQLdb/converters.py:37: DeprecationWarning: the sets module is deprecated
    from sets import BaseSet, Set

    How can I avoid this now?

  2. Flo Says:

    As before, just this time in the file converters.py on line 37, it will be similar to what needed to be done in __init__.py, line 34.

  3. MaXaTa (French) Says:

    In converters.py :

    comment line 37 : from sets import BaseSet, Set
    add after that line: BaseSet = set
    add after that line: Set = frozenset

  4. Antonio Says:

    Hi!!!

    It help me a lot.. i was looking for a simple solution due my project ;)… Thank you.. :D

  5. Antonio Says:

    By the way… I had no kind of error ;)

  6. Raji Says:

    Nice post to get rid of deprecation warning : ‘from sets import ImmutableSet’.
    Then i also received another DeprecationWarning:
    /var/lib/python-support/python2.6/MySQLdb/converters.py:37: DeprecationWarning: the sets module is deprecated
    from sets import BaseSet, Set

    From the above comment it was mentioned to do what done in __init__.py,line 34. In __init__.py line 34 was commented. If i comment the line 37 in converters.py(i.e., the line is ‘from set import BaseSet,Set’) i got following errors.

    File “connection.py”, line 2, in
    db = MySQLdb.connect(host=”localhost”, user=”root”, passwd=”home”, db=”list_animal”)
    File “/var/lib/python-support/python2.6/MySQLdb/__init__.py”, line 76, in Connect
    return Connection(*args, **kwargs)
    File “/var/lib/python-support/python2.6/MySQLdb/connections.py”, line 129, in __init__
    from converters import conversions
    File “/var/lib/python-support/python2.6/MySQLdb/converters.py”, line 130, in
    Set: Set2Str,
    NameError: name ‘Set’ is not defined

    How to remove the warning?

  7. socoro Says:

    thanks It’s help me :)

  8. Jitendra Harlalka Says:

    Thank you very much! It helped me get rid of those unwanted decrepted message errors :)

Leave a Reply