python-3.xgnudbm

Using dbm.gnu for Python 3.6.3 on macOS


I'm trying to open a .db file that is of type db.gnu. Attempting to open it with the built-in Python 3 module dbm fails with the message:

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

I understand that I have to use the gnu submodule in dbm to open this. However, I am unable to do so in Python 3.6.3 on macOS:

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'

How can I use dbm.gnu on a Mac?


Solution

  • I would try brew install gdbm

    After that I tried:

    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'>