5

我正在尝试打开一个.db类型为db.gnu. 尝试使用内置 Python 3 模块打开它dbm失败并显示以下消息:

dbm.error: db type is dbm.gnu, but the module is not available

我知道我必须使用gnu子模块dbm来打开它。但是,我无法在 macOS 上的 Python 3.6.3 中这样做:

In [1]: import dbm
In [2]: dbm.gnu
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-ddbd370a1085> in <module>()
----> 1 dbm.gnu

AttributeError: module 'dbm' has no attribute 'gnu'

如何dbm.gnu在 Mac 上使用?

4

2 回答 2

4

我已经在 pyenv 中安装了 3.6.4,所以我必须执行以下操作:

brew install gdbm

然后在那之后,我需要重新安装 3.6.4。

pyenv uninstall 3.6.4
pyenv install 3.6.4
pyenv global 3.6.4

在此之后,它按预期工作。

于 2018-03-02T18:00:36.193 回答
3

我会尝试brew install gdbm

之后我尝试了:

Python 3.6.4 (default, Jan  6 2018, 11:51:59)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbm.gnu
>>> print(dbm.gnu)
<module 'dbm.gnu' from '/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/dbm/gnu.py'>
>>> import dbm
>>> dbm.gnu
<module 'dbm.gnu' from '/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/dbm/gnu.py'>
于 2018-02-08T02:52:12.520 回答