1

我正在从 macports 运行 python 3.1.4,并尝试在这里使用搁置模块。我可以在另一个开发人员上成功使用它。机器(不同的操作系统等)所以我不确定我可能做错了什么......

任何想法或建议将不胜感激!

这是错误“dbm.error: db type could not be determined”(我搜索了错误消息但没有找到任何信息——我什至试图强制 protocl=2 看看这是否有帮助,但它没有)

下面是互动环节:

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
4

2 回答 2

1

这看起来像是 MacPorts 端口或 Python 3 中的错误。对我而言,您的示例适用于当前的 MacPorts Python 2.7.2,但与您报告的方式相同,适用于当前的 MacPorts Python 3.2.2。MacPorts 自动构建并包含gdbm作为 Python 3 端口的数据库管理器;对于 Python 2,它包括 BerkeleyDB4.6gdbm. 看起来 MacPorts 2.7.2 正在使用 db46 并且可以工作,但 3.2.2 使用gdbm; 大概 MacPorts 3.1 端口是类似的。这应该进一步调查。

更新:如果您使用的是最新的 MacPorts 安装,这可能是http://bugs.python.org/issue13007中报告的问题 看起来有一个修复程序支持最新的gdbm 1.9和更高版本 - 当前的 MacPorts版本是 1.9.1。该修复是在 Python 3.2.2 发布后应用的(它将在 3.2.3 中);MacPorts 的人应该将其反向移植到他们的 Python 端口。

于 2011-11-10T06:12:14.617 回答
0

使用 MacPorts 或 Homebrew 安装ndbm。搁置使用它来创建数据库。稍后打开文件时,shelve会调用dbm.whichdb并成功识别文件。

于 2011-11-10T05:32:58.927 回答