如何在非 BSD 系统(Ubuntu、RHEL)上用 Python 打开 Berkeley DB 1.85 文件?
$ file 1.db
1.db: Berkeley DB 1.85 (Hash, version 2, native byte-order)
我试图运行的代码:
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
这是一个例外:
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
不想安装bsddb185
模块:
$ 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)