Invoking IPython programmatically

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Invoking IPython programmatically

Frank Smith-14
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 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)] on
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\", line 58, in <module>

  File "C:\Python26\lib\site-packages\IPython\", line 37, in <module>
    from IPython import ultraTB, ipapi
  File "C:\Python26\lib\site-packages\IPython\", line 93, in <module>
    from IPython import Debugger, PyColorize, ipapi
  File "C:\Python26\lib\site-packages\IPython\", line 34, in <module>

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

On the other hand, if I leave out this ImportModule from, 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?


Python.NET mailing list - [hidden email]