I am running python 3.1.4 from macports and I am attempting to use the shelve module here. I can use it successfully on another dev. machine (different OS, etc.) so I am not sure what I may be doing incorrectly...
Any thoughts or suggestions would be greatly appreciated!
Here is the error "dbm.error: db type could not be determined" (I searched for the error message but found no info - I even tried to force the protocl=2 to see if that might help but it did not)
Here's the interactive session:
Python 3.1.4 (default, Oct 7 2011, 15:58:53)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
>>> import shelve
>>> a = [1, 2, 3]
>>> locker = shelve.open('myshelf',protocol=2)
>>> locker['a'] = a
>>> locker.close()
>>> exit()
Python 3.1.4 (default, Oct 7 2011, 15:58:53)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
>>> import shelve
>>> locker = shelve.open('myshelf',protocol=2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/shelve.py", line 231, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/shelve.py", line 215, in __init__
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/dbm/__init__.py", line 84, in open
raise error[0]("db type could not be determined")
dbm.error: db type could not be determined
This looks like a bug in the MacPorts port or in Python 3. For me, your sample works with a current MacPorts Python 2.7.2 but fails with a current MacPorts Python 3.2.2 in the same way as you've reported. MacPorts automatically builds and includes gdbm
as a database manager for Python 3 ports; for Python 2 it includes both Berkeley DB4.6
and gdbm
. It looks like the MacPorts 2.7.2 is using db46 and works but 3.2.2 fails using gdbm
; presumably the MacPorts 3.1 port is similar. This should be investigated further.
Update: If you are using an up-to-date MacPorts installation, this is likely the problem reported in http://bugs.python.org/issue13007 It looks like there was a fix to support the latest gdbm 1.9
and beyond - the current MacPorts version is 1.9.1. That fix was applied after Python 3.2.2 was released (it will be in 3.2.3); the MacPorts folks should backport that to their Python ports.