5

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?

Sean Saito
  • 655
  • 7
  • 18

2 Answers2

4

I already had 3.6.4 installed in a pyenv, so I had to do the following:

brew install gdbm

And then after that, I need to reinstall 3.6.4.

pyenv uninstall 3.6.4
pyenv install 3.6.4
pyenv global 3.6.4

After this it worked as it was supposed to.

3

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'>
Mitchell Currie
  • 2,769
  • 3
  • 20
  • 26
  • Thanks! Upgrading to 3.6.4 helped in my case, since I already had gdbm installed. – Sean Saito Feb 08 '18 at 05:22
  • I tried running those in my python shell and I get `AttributeError: module 'dbm' has no attribute 'gnu'`. Running pn ubuntu 18.04 and python 3.6.7 – lollerskates Aug 09 '19 at 18:54