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)
>>>
June 26th, 2009 at 1:08 am
Good post. The deprecated message was disturbing me
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?
June 26th, 2009 at 2:51 am
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.
August 3rd, 2009 at 3:43 pm
In converters.py :
comment line 37 : from sets import BaseSet, Set
add after that line: BaseSet = set
add after that line: Set = frozenset
August 5th, 2009 at 8:58 am
Hi!!!
It help me a lot.. i was looking for a simple solution due my project ;)… Thank you..
August 5th, 2009 at 8:59 am
By the way… I had no kind of error
August 12th, 2009 at 8:45 am
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?
November 30th, 2009 at 8:00 pm
thanks It’s help me
February 26th, 2010 at 1:01 pm
Thank you very much! It helped me get rid of those unwanted decrepted message errors