Open Berkeley DB version 1.85 in Python on a non BSD system

2.1k views Asked by At

How can I open Berkeley DB 1.85 file in Python on a non BSD system (Ubuntu, RHEL)?

$ file 1.db 
1.db: Berkeley DB 1.85 (Hash, version 2, native byte-order)

The code i am trying to run:

    import bsddb

    cur_dir = os.path.dirname(__file__)
    db_file_path = os.path.join(cur_dir, '1.db')
    db = bsddb.hashopen(db_file_path, 'r')
    for k, v in db.iteritems():
        print k, v

This is the exception:

  File "....py", line 22, in handle
    db = bsddb.hashopen(db_file_path, 'r')
  File "/usr/lib/python2.7/bsddb/__init__.py", line 364, in hashopen
    d.open(file, db.DB_HASH, flags, mode)
bsddb.db.DBInvalidArgError: (22, 'Invalid argument -- __db_meta_setup: /.../1.db: unexpected file type or format')
enter code here

pip doesn't want to install bsddb185 module:

$ pip install bsddb185
Downloading/unpacking bsddb185
  Running setup.py egg_info for package bsddb185
    Didn't find db.h with HASHVERSION == 2
No files/directores in /.../build/bsddb185/pip-egg-info (from dependency_links.txt)
2

There are 2 answers

0
Brian On

The docs recommend that this module is deprecated in favour of bsddb.db. If you're sticking with bsddb, they also have the comment, "The bsddb module requires a Berkeley DB library version from 4.0 thru 4.7."

docs: http://docs.python.org/library/bsddb.html

Hope some of this points in the right direction, sorry I couldn't be more helpful.

1
warvariuc On

OK, a colleague of mine helped me to build the module from source.

Download the source here: http://pypi.python.org/pypi/bsddb185

Then:

cd bsddb185/db.1.85/PORT/linux/
make
cd ../../..
python setup.py install