[IPython-user] embedding in C program
Amir
amirnntp@gmail....
Mon Oct 20 16:49:25 CDT 2008
Amir <amirnntp <at> gmail.com> writes:
>
> Hello.
>
> I have embedded the Python interpreter in a C program. I would like to also
> embed IPython to take advantage of it's many features.
>
> 1. I have the following basic program working, which starts up an IPython shell
> from within a C program.
>
> #include "Python.h"
>
> main(int argc, char **argv)
> {
> Py_Initialize();
>
> PySys_SetArgv(argc, argv);
> PyRun_SimpleString("from IPython.Shell import IPShellEmbed\n");
> PyRun_SimpleString("ipshell = IPShellEmbed()\n");
> PyRun_SimpleString("ipshell()\n");
>
> Py_Finalize();
> }
>
> 2. Now, I would like to run commands through the IPython shell using the Python
> C api with Py_CompileString and PyEval_EvalCode and read the result using
> commands like PyArray_Check for a returned numpy array.
>
> After instantiating an ipshell, is there a way to start it and pass commands to
> it using the C api and read from the __main__ dict? Running ipshell() will just
> start the interpreter and I wont be able to further call it from C.
>
> Thanks,
> Amir.
>
I'd like to add if anyone happens to be interested that this is part of a
Mathematica linked module that allows starting a python shell and calling python
functions transparently from Mathematica. I would like to interact with an
ipython shell rather than a python shell.
So far, what I have working is automatic recognition of numpy array types and
matplotlib plotting functions as well as the built-in Python types (lists,
tuples, booleans, etc). These are trivial extensions to the existing Pythonika
package:
http://dkbza.org/pythonika.html
In case you use Mathematica, this is handy because, among other things:
- you have the mathematica notebook interface to record results and plots,
- you can call scipy functions where no counterpart exists in Mathematica (like
some signal processing functions),
- call R or cvxopt,
- call Sage (haven't done this yet).
More information about the IPython-user
mailing list