Embedding Python, PyImport_* etc etc...
t o b e
tbradshaw at orchestream.com
Fri Dec 22 18:39:43 CET 2000
First of all Merry Xmas, everybody.. and a very Happy New Year to you all...
also apologies to the SWIG guys to whom this doesn't *directly* apply but
who I figured would be very likely to know or be interested in the answers
to this problem..
Well, I'm nearing the end of my embedding project and am now trying to tie
up all the loose ends here.. One of my primary goals is that we should ship
1 executable file only and to this end I have been trying to find a way to
bind those files normally residing externally in .py files into our
>From this work arises a couple of questions:
My first take on the problem was to add the .py files to my project as
strings and then do this to them (after calling Py_Initialise(), of course
pMyModule = Py_CompileString(strMyModule, "import.tmp", Py_file_input);
if (pMyModule) PyImport_ExecCodeModule ("MyModule", pMyModule); else
For modules with no dependencies this seems to work fine.. even for modules
that import other modules this worked as long as I was careful about the
order in which I did things. However, I then started running into circular
dependencies (e.g. os.py and ntpath.py which import each other) for which
there was no right order in which to make the calls. I found that calling
PyImport_AddModule() for everything before I began importing alleviated this
problem but now I'm having problems with sre_constants.py (dependency of
sre) which doesn't seem to be exporting all of its contstants properly
(could this be becuase it is imported using the from * syntax)...
Anwyay.. the long and the short of it is.. does it look like I'm going about
this the right way and if not, which do you think would be the correct
t o b e
More information about the Python-list