[Xapian-devel] Building Xapian on Mac OSX 10.6.x
James Aylett
james-xapian at tartarus.org
Sat Mar 26 16:07:59 GMT 2011
On 26 Mar 2011, at 15:43, Ira Ray Jenkins wrote:
> When I try to import I get the following error:
>
>>>> import xapian
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/python/site-packages/xapian/__init__.py", line 28, in <module>
> _xapian = swig_import_helper()
> File. "/python/site-packages/xapian/__init__.py", line 27, in swig_import_helper
> return _mod
> UnboundLocalError: local variable '_mod' referenced before assignment
That code is generated by SWIG:
if fp is not None:
try:
_mod = imp.load_module('_xapian', fp, pathname, description)
finally:
fp.close()
return _mod
I rarely use try…finally, but it looks to me that if an exception is raised during the try block, the return statement will raise an exception during the finally block. This is exactly what you're seeing here. I think the code should actually be something like:
if fp is not None:
try:
_mod = imp.load_module('_xapian', fp, pathname, description)
fp.close()
return _mod
finally:
import _xapian
return _xapian
(which could actually be done better by collapsing with the code immediately above, I think)
but would appreciate someone who's used the imp python stuff checking this over. Whatever, it shouldn't explode like that, which looks like a SWIG bug to me.
> I believe, from various googling, that the error is a failed import of xapian. So, do you have any ideas or solutions I can try? Thanks,
Make sure you're not running python inside the xapian-bindings/python build directory; that confuses the import mechanism. (I got exactly the exception you did running in the build directory, and not elsewhere; this is a common problem with building python extensions.)
J
--
James Aylett
talktorex.co.uk - xapian.org - devfort.com - spacelog.org
More information about the Xapian-devel
mailing list