Adjusting to the new version of Pylab and Mayavi on Ubuntu 12.04

It seems the IPython and Pylab packages has also been updated in 12.04 and thus removing the old ipython -wthread flag that would ensure Mayavi plots to be run in a separate thread. Running with the flag causes this error to show up:

[TerminalIPythonApp] Unrecognized flag: '-wthread'

Without this flag, the Mayavi plots lock up the UI and hangs. If you want to get the possibility back to rotate and play around with the plots, just start IPython the following way from now on:

ipython --pylab=qt

This will launch IPython with the Qt backend and threading. Using only –pylab does not include threading. For easy and quick access, add the following to a file named .bashrc in your home folder:

alias pylab='ipython --pylab=qt'

From now on you can launch IPython just by typing

pylab

in a terminal.

Using the same script on installs with different EPD versions

In the newest version of Enthought’s Python Distribution (EPD) on Ubuntu, the plotting package has been moved from enthought.mayavi.mlab to the shorter and more general mayavi.mlab. This does however mean that if you, like me, need to work with different versions of EPD on multiple systems, will experience the following error from time to time:

ImportError: No module named enthought.mayavi.mlab

Now, to avoid switching the import statement every time you switch systems, you can make Python check if one of the versions is installed during import. If it is not, we’ll tell it to try the other. This is done in this simple command:

try:
    from enthought.mayavi.mlab import *
except ImportError:
    from mayavi.mlab import *

Just replace any other similar import statements the same way and your code should once again be working across all your installations.

LaTeX It! (and a new blog)

Together with my good friend, Mikael, I’ve started a blog about physics, chemistry, maths and technology over at Mindseye.no. Some of my postings over there will be dual posted here. Especially those about technical notes and tutorials. This is the first one, about LaTeX equations in Thunderbird.

If you are using Thunderbird for e-mail and want to send mathematical formulas to your contacts, you should consider the LaTeX It! plugin or the Equations plugin. The former requires you to have LaTeX and ImageMagick installed, while Equations uses an external server to generate your images.

There are a few pros and cons to both approaches. If you are using the Equations plugin, your images won’t be integrated in your e-mail as files, but will simply be linked to. You will see the images, of course, but if the server should crash or no longer be operative, your LaTeX formulas will become invisible.

This will probably not happen in the nearest future, but if you want to see your formulas forever, it might be a good idea to use LaTeX It! instead.

The problem with LaTeX It! is that it requires your computer to have the right set of packages installed. In Ubuntu this is no problem – you just install the packages texlive-latex-base, texlive-binaries and imagemagick using either Synaptic or by issuing the following command in a Terminal:

sudo apt-get install texlive-latex-base texlive-binaries imagemagick

In Windows you need to install LaTeX and ImageMagick by using the automatic installers, and you will also need GhostScript. On a Mac, however, I’ve not yet got the installation to work. You could try to see if everything is installable from MacPorts, but I have been unlucky with the converting, and would suggest you use the Equations plugin if everything else fails.

LaTeX It!

This is going to my first post in this blog, and along with some other more technical posts, I will dual post it in my own blog over at dragly.org.

If you are using Thunderbird for e-mail and want to send mathematical formulas to your contacts, you should consider the LaTeX It! plugin or the Equations plugin. The former requires you to have LaTeX and ImageMagick installed, while Equations uses an external server to generate your images.

Continue reading