Ok so I'm having trouble actually suppressing this thing. The problem is that to detect whether umfpack is present we try to build the UmfpackContect() object:
try:
from scipy.sparse.linalg.dsolve import umfpack
UmfpackContext = umfpack.UmfpackContext()
except:
UmfpackContext = None
The constructor raises an ImportError, which we duly catch (although that line should really specify the error type, but whatever). Unfortunately, the UmfpackContext class has a destructor (__del__) which then tries to delete some objects that were never created and raises an AttributeError — which, since we are already in a try: except: clause, gets ignored, hence the message to stderr.
Basically this is a bug in scipy I think?
The standard approach is to temporarily redirect stderr to /dev/null, and this works interactively:
In [1]: from scipy.sparse.linalg.dsolve import umfpack
In [2]: try:
UC = umfpack.UmfpackContext()
except ImportError:
print 'hello'
...:
hello
Exception AttributeError: "'UmfpackContext' object has no attribute '_symbolic'" in <bound method UmfpackContext.__del__ of <scipy.sparse.linalg.dsolve.umfpack.umfpack.UmfpackContext object at 0x103938250>> ignored
In [3]: import sys, os
In [4]: null = open(os.devnull, 'w')
In [5]: null.write('hello!')
In [6]: sys.stdout.write('hello!')
hello!
In [7]: sys.stderr.write('hello')
hello
In [8]: sys.stderr = null
In [9]: sys.stderr.write('hello')
In [10]: try:
UC = umfpack.UmfpackContext()
except ImportError:
print 'hello'
....:
hello
In [11]: sys.stderr = sys.__stderr__
In [12]: sys.stderr.write('hello')
hello
However, doing this in the code doesn't work, even when I try to flush the redirected stderr! (I'm not even sure that makes sense!)
sys.stderr = open(os.devnull, 'w')
try:
from scipy.sparse.linalg.dsolve import umfpack
UmfpackContext = umfpack.UmfpackContext()
except:
UmfpackContext = None
finally:
sys.stderr.flush()
sys.stderr = sys.__stderr__
Thoughts/ideas?