Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 874
Sean Saito Avatar asked Mar 07 '23 22:03

Sean Saito


2 Answers

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.

like image 191
Johan Thorén Avatar answered Mar 10 '23 23:03

Johan Thorén


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'>
like image 31
Mitchell Currie Avatar answered Mar 11 '23 00:03

Mitchell Currie