15

I installed python3.6 in windows machine. And get below error while open my.db file.

my.db file created by my program in ubuntu16.04 in python3.6, using shelve module.

In [1]: import shelve

In [2]: db = shelve.open("etc/my.db")
---------------------------------------------------------------------------
error                                    Traceback (most recent call last)
<ipython-input-2-b4828c8ee6e1> in <module>()
----> 1 db = shelve.open("etc/my.db")

c:\Python36\Lib\shelve.py in open(filename, flag, protocol, writeback)
    241     """
    242
--> 243     return DbfilenameShelf(filename, flag, protocol, writeback)

c:\Python36\Lib\shelve.py in __init__(self, filename, flag, protocol, writeback)
    225     def __init__(self, filename, flag='c', protocol=None, writeback=False):
    226         import dbm
--> 227         Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
    228
    229

c:\Python36\Lib\dbm\__init__.py in open(file, flag, mode)
     89     elif result not in _modules:
     90         raise error[0]("db type is {0}, but the module is not "
---> 91                        "available".format(result))
     92     else:
     93         mod = _modules[result]

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

Please help, how can I install a missing module in windows.

4
  • any fix to share? Commented Oct 31, 2018 at 1:15
  • 1
    Not yet. Issue occur only when file created by unix and you try to open in windows. If you creating new file, it is working. But it is not creating file with ".db" extension. Commented Oct 31, 2018 at 10:37
  • 1
    Try to delete pycache folder Commented Mar 2, 2021 at 10:47
  • I also encounter this issue when I try to read a .db file on WIndows, the file was created on Linux. Commented Apr 2, 2023 at 8:40

2 Answers 2

3

The only way I found to fix this error was to install a missing component on my Ubuntu after the upgrade to python3.10

sudo apt-get install python3.10-gdbm
Sign up to request clarification or add additional context in comments.

1 Comment

for debian: apt-get install python3-gdbm
1

As mentioned by @alexander-p , the problem might be the __pycache__ folders in your source code.

In my case was that I did replace a venv folder with a virtual environment by a new folder with the same name but a newer version of Python (~3.8~ → 3.9), and using at the same time PyCharm (that used the venv setup).

Deleting all the Python caches (and restarting PyCharm just in case) solved the problem.

You can do so with:

$ find . -name __pycache__ | xargs rm -Rv

If the venv folder is inside the same folder where your source code is placed, better to execute:

$ find . -name __pycache__ | grep -v venv | xargs rm -Rv

So the cache inside the venv/ folder is not deleted.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.