Ah, that is maybe the idea:
On Wed, Feb 3, 2010 at 03:41, David Cournapeau <cournape@gmail.com> wrote:Or rather, to recover from the failed import as the OP wants to do:
> On Wed, Feb 3, 2010 at 5:38 PM, Peter Notebaert <peno@telenet.be> wrote:
>> >From an extension? How to import numpy from there and then test if that
>> succeeded and that without any annoying message if possible...
>
> One obvious solution would be to simply call PyImport_Import, something like:
>
> #include <Python.h>
>
> PyMODINIT_FUNC initfoo(void)
> {
> PyObject *m, *mod;
>
> m = Py_InitModule("foo", NULL);
> if (m == NULL) {
> return;
> }
>
> mod = PyImport_ImportModule("numpy");
> if (mod == NULL) {
> return;
> }
> Py_DECREF(mod);
/* Clear the error state since we are handling the error. */
mod = PyImport_ImportModule("numpy");
if (mod == NULL) {
PyErr_Clear();
/* ... set up for the sans-numpy case. */
}
else {
Py_DECREF(mod);
import_array();
/* ... set up for the with-numpy case. */
}
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion