Embedding pure python statically -- possibly a newbie question

Geoff Wedig wedig at darwin.epbi.cwru.edu
Wed Jan 18 12:22:35 EST 2006


I have inherited a project with an embedded python interpretter, and 
don't know much about it, but have been given the task of porting it to 
a new compiler/OS and have run into some problems.

I seem to have got the embedded interpretter part of it working, and 
have worked out how to add c modules to extend it.  My problem is 
embedding pure python code so that I don't have to have external .py 
files to my application.

What I mean is, if I have a module, foo.py, I'd like to somehow have its 
code as part of my application executable, so when the application does, 
for example,

PyImport_ImportModule("foo");

it won't look for a foo.py, but use the internal static version.  The C 
style modules do this, so I imagine it can be done with pure python as 
well, but I've not figured out *how*.  I can a C wrapper to do this 
(embedding python in C in python in....), but I figure there has to be 
another way.

I've been going over the docs, and haven't gotten very far, so it's 
possible this is answered there.  If so, just give me a nudge/push/shove 
in the right direction.

Thanks for any help!




More information about the Python-list mailing list