How to get gdbm module?

I’ve been using Conda for a few years as a convenient installation, mostly because I use Jupyter notebooks from time-to-time and it with all its dependencies installs with no problem.

At the moment, I’m working on a Python3 port of SpamBayes and am trying to fill in some missing modules. Gdbm is my current stumbling block:

% python
Python 3.9.13 (main, Aug 25 2022, 23:26:10)
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import dbm.gnu
Traceback (most recent call last):
File “”, line 1, in
File “/home/skip/miniconda3/envs/python39/lib/python3.9/dbm/gnu.py”, line 3, in
from _gdbm import *
ModuleNotFoundError: No module named ‘_gdbm’

I installed the conda gdbm package, but that just installed some shell level tools, not the desired dbm.gnu stuff. Python 3.10.4 seems to have it:

% /usr/bin/python3
Python 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import dbm.gnu
>>> dir(dbm.gnu)
(‘builtins’, ‘cached’, ‘doc’, ‘file’, ‘loader’, ‘name’, ‘package’, ‘spec’, ‘error’, ‘open’, ‘open_flags’)

I see nothing in conda search output which would suggest gdbm is available. I can switch to 3.10 without much trouble, but why gdbm is nowhere to be found in Conda.

1 Like

dear skip.montanaro.

Thank you for your posting.

The cause of the error is unknown, but “_gdbm.cpython-39-x86_64-linux-gnu.so”, which should exist under “/lib/python3.9/lib-dynload/”, does not exist. .

If another version of the corresponding library exists, copying it to the above directory will solve the problem.

Reference URL: python - No module named '_gdbm' - Stack Overflow

We apologize for the inconvenience, but thank you in advance.

Regards, you.
ktsh.tanaka.2020

Thanks. My Ubuntu system is already on 3.10, so the 3.9 workaround you mentioned isn’t available. I guess it’s time to create a python310 Conda environment.

dear skip.montanaro.

thank you for your reply.
To run gdbm with python3.10, it will be “_gdbm.cpython-310-x86_64-linux-gnu.so”, so please do not make a mistake.

I wish you every success.
Best regards
Ktsh.tanaka.2020

Yup, symlink does the trick and leaves evidence that something out of the ordinary happened.

dear skip.montanaro.

thank you for your reply.
You don’t really need a symbolic link.
Copy “_gdbm.cpython-310-x86_64-linux-gnu.so” directly to “/home/“user”/anaconda3/envs/py310/lib-dynload”.

after that,

sudo chown “user” _gdbm.cpython-310-x86_64-linux-gnu.so

must be implemented. Otherwise Python installed in anaconda will print import error again.

Best regards
ktsh.tananka.2020

Sure, but a symlink doesn’t require a sudo/chown step, and as I indicated, the fact that it’s a symlink leaves a little morsel suggesting something out of the ordinary is going on.