views:

1207

answers:

2

Do the following on the default Python install on Mac OS X 10.5 (Leopard) w/ Developer Tools:

noel ~ : python

Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bsddb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
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

nice, huh? How do I fix this without giving up and installing/configuring/maintaining my own Python package as per TMNC's suggestion or using MacPorts etc?

Edit

I've gone around the problem by installing Python2.4 and BSDDB via MacPorts.

My question still stands: why is the default install broken and is it possible to fix it.

+1  A: 

Macports is easy and very powerful. Why don't you want to use it?

xkcd150
I'm lazy. Everything I want is installed already (python 2.4, bsddb). It's just broken by default. Why duplicate it?Also, the default brokenness is a joke. A fix should be documented *somewhere*. Is every single person who tries to do this supposed to give up and wander off on their own to MacPorts et al?
Noel
You'd duplicate it because any changes you make will be removed by the vendor during an update — and there's no guarantee they won't break it further. Go use MacPorts.
Nerdling
Your point is taken, and I have. But I'd still like to know if it's possible to fix the default install too.
Noel
+5  A: 

Follow the instructions at http://marc-abramowitz.com/archives/2007/11/28/hacking-os-xs-python-dbhash-and-bsddb-modules-to-work/ .

Alex Martelli
Yeah, I ran across that too. It's not the answer I'm looking for, in that you have to install/maintain another version of bsddb yourself. I am looking for a way to fix the default install of bsddb.
Noel
This is a good suggestion... it isn't that you're installing/maintaining another version bsddb, you're installing the first one that works :-) There is no _bsddb anywhere on the system, so you're going to have to do something to produce the missing functionality that's required.
Jarret Hardie
You're right that there isn't a _bsddb module, but there is a bsddb module. I'm asking for a technical explanation of why _bsddb is there, and if it is possible to change the behavior to use that bsddb.
Noel
the bsddb module tries to load the _bsddb extension -- but the latter can only be built if libbsddb is present, and it isn't by default on MacOSX. So, Abramowitz shows one way you can remedy that. There is no way you can use the bsddb module if the latter can't load the underlying _bsddb one, so that's what you must remedy.
Alex Martelli
Thanks! The one point I was confused on Abramowitz's explanation was the modifications to the dbhash.py file--AFAIK, I'm not interested in importing *both*. Will it suffice to just get the bsddb3 installed, no hackery of dbhash required if I just want to import bsddb?
Noel
Alex Martelli