[Python.NET] Invoking IPython programmatically

Frank Smith frankiansmith at gmail.com
Sat Feb 12 16:06:59 CET 2011

Hello everyone,

I am relatively new to Python.NET, and I think that it will serve me very
well for the application that I am developing.

I am taking an application that had previously been implemented using
Python/wxPython/matplotlib/numpy/scipy, and reimplementing it using .NET 4.
The main reason that I'm doing this is because the application used to be
used primarily by technical people comfortable to working in a Linux
environment, but I am interested in making it usable by the Windows crowd.

On the other hand, I don't want to give up the ability to script the
application with Python, and I don't want to give up using
matplotlib/numpy/scipy. This is what has led me to Python.NET.

Following the email trail, I have been able to get the Console test program
running using VS2010 targeting .NET 4. What I'm now interested in doing is
to get IPython to load automatically, so the user does not have to manually
import IPython then call the IPShell mainloop. I am using Python 2.6.6,
IPython 0.10.1, pyreadline 1.6.2 all on XP SP3 win32.

So I modified pythonconsole.py like this:

    public static int Main(string[] args) {
        string [] cmd = Environment.GetCommandLineArgs();

        PyObject ip = PythonEngine.ImportModule("IPython");    <<<<<< new

        int i = Runtime.Py_Main(cmd.Length, cmd);

        return i;

Unfortunately, ImportModule returns null.  Then, from the command line, if I
manually import IPython, I get this

Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
Type "help", "copyright", "credits" or "license" for more information.
>>> import IPython
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\lib\site-packages\IPython\__init__.py", line 58, in

  File "C:\Python26\lib\site-packages\IPython\Shell.py", line 37, in
    from IPython import ultraTB, ipapi
  File "C:\Python26\lib\site-packages\IPython\ultraTB.py", line 93, in
    from IPython import Debugger, PyColorize, ipapi
  File "C:\Python26\lib\site-packages\IPython\Debugger.py", line 34, in

    from IPython import PyColorize, ColorANSI, ipapi
ImportError: cannot import name PyColorize

On the other hand, if I leave out this ImportModule from pythonconsole.py,
and manually import IPython from the command line, it imports successfully,
and furthermore I can run the IPython mainloop.

Ultimately, what I really want to accomplish is to get my .NET 4 application
to present the user with an IPython shell that has a .NET "Application"
object injected into its namespace, so the user can start interacting with
the .NET objects from the application, but also be able to do matplotlib
type stuff too.

Does anyone have any thoughts as to why I'm having problems importing
IPython programmatically?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20110212/937b4106/attachment.html>

More information about the PythonDotNet mailing list