[Qgis-developer] Announcing an IPython plugin

Charlie Sharpsteen chuck at sharpsteen.net
Fri Aug 19 14:53:15 EDT 2011


New (Experimental!) Plugin
====================

I just uploaded an alpha version of a plugin that allows an IPython kernel
to be integrated into QGIS. This in turn allows external IPython-powered
consoles to connect to QGIS and execute commands or inspect data. Version
0.2 of the plugin is now available from PyQGIS and is flagged
"Experimental":

    http://spatialserver.net/pyqgis_1.0/contributed/ipython_console.zip

I am making the announcement here, because I feel that the current state of
the plugin makes it most interesting to developers. I have tested the plugin
with QGIS 1.7.0 on OS X 10.6 and Ubuntu 11.4 and it appears to be usable.

Bug reports and pull requests are welcomed at GitHub:

  https://github.com/Sharpie/qgis-ipython


What is IPython?
=============

IPython is a __really__ nice shell for performing interactive work in the
Python programming language. Some killer features IPython provides compared
to the standard Python console are:

  - Tab completion for object and method names.
  - Function call tips that provide information about arguments on-the fly.
  - Easy access to docstrings.
  - "magic" commands that allow users to turn complex function calls into
simple, customized command lines.

Additionally, the v0.11 release completely re-factored the project and
brought about many exciting changes:

  - A distributed two-process system where computational kernels handle the
details of executing code and may be controlled by one or more console
processes that handle the details of sending user input and formatting
kernel output.
  - A new PyQt-based console with plenty of neat tricks such as
Pygments-based highlighting of source code and inline display of Matplotlib
graphs.
  - A high-level framework for performing parallel computing in an
interactive fashion.

For more information about IPython, see:

  The IPython website:
    http://www.ipython.org

  The manual section on interactive computing:
    http://ipython.org/ipython-doc/stable/interactive/index.html

  A talk by Fernando Perez at SciPy 2011 which details many features of
v0.11:

http://www.archive.org/details/Wednesday-203-6-IpythonANewArchitectureForInteractiveAndParallel


How Does the Plugin Work?
=====================

The IPython plugin requires following dependencies to be installed:

  - Python 2.6 or 2.7
  - IPython v0.11 or v0.12-dev
  - PyZMQ
  - Pygments
  - Matplotlib

Unfortunately, Windows users are currently out of luck as QGIS appears to be
pinned to the version of Python provided by OSGEO4W which is currently at
2.5.x.

The plugin provides one new entry to the "Plugins" menu called "External
IPython Console". This launches an external process, based on
`ipython-qtconsole`, that communicates with an IPython kernel __running
inside of QGIS__. This means that every command entered through the console
is actually executed inside of QGIS.

The only downside I have noticed to running the console in a
process separated from QGIS is that the IPython console window cannot be
docked or otherwise integrated into the QGIS GUI.

__IMPORTANT NOTE__

One currently has to be careful when closing external Python consoles
because they can terminate the IPython kernel running inside of QGIS which
has the unfortunate side effect of causing QGIS to quit. The recommended way
to shut down an external console is to close the window and select "No, just
this Console" when asked if you would like to quit the Kernel. Choosing
"Yes, quit everything" or running the `exit()` command in the IPython shell
will cause QGIS to quit as well.

I am working on finding a way around this issue so that it will be more
difficult for users to accidentally terminate QGIS when all they wanted to
do was close the IPython console.


Future Directions
=============

There are plenty of things that need to be cleaned up in order to achieve a
smoother user interface such as better error messages and figuring out how
to handle situations where the kernel dies and needs to be restarted.

There are also many exciting possibilities that could be explored such as
using the parallel computing framework to build faster tools for GIS
analysis or using the IPython communication protocol make it easier for
other programs to communicate with QGIS.

If QGIS upgrades to version 2 of the SIP API, another exciting development
possibility is to replace the current Python console with an IPython console
that does not run in a separate process.

I have done some initial work on this front and managed to get a
proof-of-concept build that successfully ran the IPython console:

    https://github.com/Sharpie/Quantum-GIS/tree/ipython-console

The biggest challenge in upgrading to version 2 of the SIP API appears to
finding areas in the Python code where QString methods are used and
replacing them with equivalent Python string methods. The branch above is
very much an experiment---many things were simply commented out.


-Charlie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20110819/504f3ad1/attachment.html


More information about the Qgis-developer mailing list