By default on my Leopard system, the dbhash and bsddb Python modules cannot be loaded.
marc@hyperion:~$ python Python 2.5.1 (r251:54863, Oct 5 2007, 21:08:09) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import dbhash Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/System/Library/Frameworks/Python.framework/Versions/2.5 /lib/python2.5/dbhash.py", line 5, in <module> import bsddb File "/System/Library/Frameworks/Python.framework/Versions/2.5 /lib/python2.5/bsddb/__init__.py", line 51, in <module> import _bsddb ImportError: No module named _bsddb
I managed to get it to work though by installing bsddb3 from the pybsddb site and hacking the file /System/Library/Frameworks/Python.framework/Versions/2.5
:
/lib/python2.5/dbhash.py
marc@hyperion:~$ diff -u dbhash.py.orig dbhash.py --- dbhash.py.orig 2007-11-28 10:16:33.000000000 -0800 +++ dbhash.py 2007-11-28 10:36:52.000000000 -0800 @@ -2,7 +2,7 @@ import sys try: - import bsddb + import bsddb3 as bsddb except ImportError: # prevent a second import of this module from spuriously succeeding del sys.modules[__name__]
Here’s the patch.
Now it works:
marc@hyperion:~$ python Python 2.5.1 (r251:54863, Oct 5 2007, 21:08:09) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import dbhash >>> dir(dbhash) ['__all__', '__builtins__', '__doc__', '__file__', '__name__', 'bsddb',
'error', 'open', 'sys']
Hrm. Long story, but I’m trying to get cvs2svn to work on Leopard, and that requires a working bsddb module.
I can’t actually get pybsddb to build:
distutils/sysconfig.py”, line 389, in _init_posix
raise DistutilsPlatformError(my_msg)
distutils.errors.DistutilsPlatformError: $MACOSX_DEPLOYMENT_TARGET mismatch: now “10.4” but “10.5” during configure
How did you get on with that part?
Nice post. I’ve followed your instructions and can import dbhash, but am still getting the following code error:
dbm = bsddb.hashopen(bdb_name, ‘n’)
NameError: global name ‘bsddb’ is not defined
Any advice you have will be much appreciated.
Thanks,
-k.
And actually, the code used to state “import bsddb”, which produces an error itself. “import dbhash” does work w/o problem as you show.
Am I missing something or is the post above regarding the _bsddb module hack incomplete? What file did you actually hack below — I don’t understand how the logic flows below and what file you are actually editing…
I managed to get it to work though by installing bsddb3 from the pybsddb site and hacking the file /System/Library/Frameworks/Python.framework/Versions/2.5:
marc@hyperion:~$ diff -u dbhash.py.orig dbhash.py
— dbhash.py.orig 2007-11-28 10:16:33.000000000 -0800
+++ dbhash.py 2007-11-28 10:36:52.000000000 -0800
@@ -2,7 +2,7 @@
import sys
try:
– import bsddb
+ import bsddb3 as bsddb
except ImportError:
# prevent a second import of this module from spuriously succeeding
del sys.modules[__name__]
Worked great for me. Thanks for posting this.
cool patch, cheers.
Pingback: sudo easy_install bsddb3 error :Can't find a local Berkeley DB installation | BlogoSfera
Pingback: Installing bsddb package - python | BlogoSfera
I noticed that you posted this problem about Python 2.5 more than six years ago.
I just downloaded a brand new Anaconda installation, and I seem to be getting the same issue in Python 2.7.5:
File “//anaconda/lib/python2.7/bsddb/__init__.py”, line 67, in
import _bsddb
ImportError: No module named _bsddb
Is it possible that this issue really hasn’t been fixed in 6+ years, or do you think this is a different issue?
I’m reluctant to muck around in things like this without knowing what I’m doing.
Thanks!
Tried many recipies, what finally worked was to (1) install db53 from macports, (2) download and unpack bsddb3 source (https://pypi.python.org/pypi/bsddb3/6.1.0) and, and (3):
sudo python setup.py –berkeley-db-incdir=/opt/local/include/db53 –berkeley-db-libdir=/opt/local/lib/db53 install
I did not manage with “port install py-bsddb3” to install bsddb3 into a virtualenv.
Pingback: Python:Installing bsddb package – python – IT Sprite
Is there a way to make this work on python that’s installed on virtualenv?
as There’s no dbhash.py file there.
Is there a way to make this work on python which installed on a virtualenv?
Pingback: installation - L'installazione di bsddb pacchetto python
Pingback: Installing bsddb package - python - iZZiSwift
Pingback: module _bsddb not found error when trying to install planet library on Mac OS X - Boot Panic