在MacOS上使用dbm.gnu进行python 3.6.3



我正在尝试打开一个类型db.gnu.db文件。尝试使用内置Python 3模块dbm打开它的消息失败:

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

我知道我必须使用dbm中的gnu子模块打开此功能。但是,我无法在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'

如何在Mac上使用dbm.gnu

我已经在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

之后,它正如应有的。

我会尝试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'>

最新更新