Embedded Python (in C) example.

jbi130 at yahoo.com jbi130 at yahoo.com
Tue Feb 4 21:36:05 EST 2003


Hi..

I'm looking into embedding Python into a C application but am having
some trouble with the example given in the documentation
(http://www.python.org/doc/current/ext/pure-embedding.html).

Note that this is also a learning exercise in Python for me as well.

I have the example compiling fine as 'call', just as in the example,
and I made a small python script, multiply.py in the same directory as
my binary that contains the same text as the example

--- multiply.py ---
def multiply(a,b):
    print "Thy shall add", a, "times", b
    c = 0
    for i in range(0, a):
        c = c + b
    return c
--- end ---

I run the program as in the example but get an error..
$ ./call multiply 2 2
ImportError: No module named multiply
Failed to load "multiply"

Adding .py doesn't help either.

This is on RedHat 8.0 (x86) with Python 2.2.1.

Is there something missing from the example to make it work?

Also, my hope is to embed Python in an application in such away that
it can be be used on systems without a Python environment installed.
I don't think there should be any issues with this, but would like to
be sure.

Thanks.






More information about the Python-list mailing list