Embedded Python (in C) example.

jbi130 at yahoo.com jbi130 at yahoo.com
Wed Feb 5 03:36:05 CET 2003


I'm looking into embedding Python into a C application but am having
some trouble with the example given in the documentation

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.


More information about the Python-list mailing list