This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Importing anydbm generates exception if _bsddb unavailable
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: skip.montanaro Nosy List: fdrake, loewis, skip.montanaro, vargish
Priority: normal Keywords:

Created on 2003-05-02 17:56 by vargish, last changed 2022-04-10 16:08 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bsddb185.diff skip.montanaro, 2003-05-05 14:27
Messages (8)
msg15823 - (view) Author: Nick Vargish (vargish) Date: 2003-05-02 17:56
The anydbm module attempts to import the dbhash module,
which fails if there is no BSD DB module available.

Relevant portion of backtrace:

  File "/diska/netsite-docs/cgi-bin/waisdb2.py", line
124, in _getsystemsdbm
    dbsrc = anydbm.open(self.dbfile)
  File
"/usr/local/python-2.3b1/lib/python2.3/anydbm.py", line
82, in open
    mod = __import__(result)
  File
"/usr/local/python-2.3b1/lib/python2.3/dbhash.py", line
5, in ?
    import bsddb
  File
"/usr/local/python-2.3b1/lib/python2.3/bsddb/__init__.py",
line 40, in ?
    import _bsddb
ImportError: No module named _bsddb

Tests that explicitly use "import dbm" rather than
anydbm are successful on this system.
msg15824 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2003-05-03 09:02
Logged In: YES 
user_id=21627

I think this is not a bug. open() has determined that this
is a bsddb file, but bsddb is not supported on the system.

Or did you mean to suggest that opening the very same file
with dbm would be successful?
msg15825 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2003-05-05 14:27
Logged In: YES 
user_id=44345

I believe the attached patch does what's necessary to get this to work again.
It does a few things:
  * setup.py builds the bsddb185 under the right (restrictive) circumstances.
    /usr/include/db.h must exist and HASHVERSION must be 2.  In this case
    the bsddb185 module will be built without any extra includes, libraries
    or #defines, forcing whatever is present in /usr/include/db.h and libc to
    be used to build the module.

  * whichdb.py detects the older hash file format and returns "bsddb185".

  * bsddbmodule.c grows an extra undocumented attribute, "open".

The last two changes avoid having to change dbhash.py in complicated
ways to distinguish between new and old file versions.  The format-
detecting mess remains isolated to whichdb.py.

Using this setup I was successfully able to open /etc/pwd.db on my
system using anydbm.open(), which I was unable to do previously.  I can
also still open a more recent hash file created with anydbm.open.  Finally,
new files created with anydbm.open are in the later format.

Please give it a try.
msg15826 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2003-05-05 20:34
Logged In: YES 
user_id=21627

I can't actually test the patch, but it looks good to me.
Please apply!
msg15827 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2003-05-05 21:55
Logged In: YES 
user_id=21627

Actually, you probably need to check whether
/usr/lib/libdb.* is present, and link with that as well if
it is.

If you are uncertain whether this is the right library, I
see no way except to run a test program, at configure time,
that creates a database and determines whether this really
is a DB 1.85 database. Alternatively, the test program might
try to invoke db_version. If the function is available, it
is DB x, x>=2 (DB1 apparently has no version indication
function).
msg15828 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2003-05-06 20:54
Logged In: YES 
user_id=44345

Assigned to Fred for doc review - I added a couple notes to libbsddb.tex
and libundoc.tex in lieu of actually creating a separate bsddb185 section
which I felt would have given people the mistaken idea that the module is
available for general use.  Still, I thought there should be some mention in
the docs.

Library detection probably needs a little tweakage as well.
msg15829 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2004-06-24 06:09
Logged In: YES 
user_id=3066

The doc changes look mostly fine to me (and I've changed
what didn't; a small cosmetic nit).

I'm just amazed we're still spending time tweaking BSD DB; I
don't think that's ever "just worked" for me without digging
around for a version of the underlying library that worked
with Python.
msg15830 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2005-05-23 01:38
Logged In: YES 
user_id=44345

ancient history i just never closed
History
Date User Action Args
2022-04-10 16:08:31adminsetgithub: 38426
2003-05-02 17:56:07vargishcreate