embedding python - PyImport_ImportModule returns null

Alex Martelli aleax at aleax.it
Thu Mar 6 10:34:56 CET 2003

Bjorn Pettersen wrote:

>> From: JW [mailto:jkpangtang at yahoo.com]
>> I am trying to embed python within a c program, but I can't get
>> PyImport_ImportModule() command to load my module.
>> Please let me know what I'm doing wrong.
> [..]
> I know of at least four people who've given up on that route, and
> instead done:
>   PyObject* res = PyRun_String("import module\n", Py_file_input, namesp,
> namesp);
> res will be NULL on error, a reference to Py_None otherwise. You can
> grab a PyObject* to the module from the namespace dicts you passed in.
> If anyone knows how to do it with purely API calls, I'm all ears <wink>.

PyImport_ImportModule bypasses import hooks.  PyImport_Import doesn't,
and thus it's what you should normally use unless you're specifically
_trying_ to bypass whatever hooks are set.  Is that your problem...?


More information about the Python-list mailing list