GNU Info

Info Node: (python2.1-ext.info)Embedding Python in Another Application

(python2.1-ext.info)Embedding Python in Another Application


Next: Reporting Bugs Prev: Building C and C++ Extensions on Windows Up: Top
Enter node , (file) or (file)node

Embedding Python in Another Application
***************************************

Embedding Python is similar to extending it, but not quite.  The
difference is that when you extend Python, the main program of the
application is still the Python interpreter, while if you embed Python,
the main program may have nothing to do with Python -- instead, some
parts of the application occasionally call the Python interpreter to
run some Python code.

So if you are embedding Python, you are providing your own main
program.  One of the things this main program has to do is initialize
the Python interpreter.  At the very least, you have to call the
function `Py_Initialize()' (on MacOS, call `PyMac_Initialize()'
instead).  There are optional calls to pass command line arguments to
Python.  Then later you can call the interpreter from any part of the
application.

There are several different ways to call the interpreter: you can pass
a string containing Python statements to `PyRun_SimpleString()', or you
can pass a stdio file pointer and a file name (for identification in
error messages only) to `PyRun_SimpleFile()'.  You can also call the
lower-level operations described in the previous chapters to construct
and use Python objects.

A simple demo of embedding Python can be found in the directory
`Demo/embed/' of the source distribution.

Embedding Python in C++
Linking Requirements

automatically generated by info2www version 1.2.2.9