Thursday, 1 December 2011

If matplotlib complains about the backend in OS X...

If matplotlib works fine, but will crash or give errors whenever it's supposed to plot a graph, even with a simple instruction as:

import matplotlib.pyplot as plt 

it is likely that there is a problem with the backend that is being used.

Edit the file:


(create it if it doesn't exist)

and add the line:

backend: MacOSX

Monday, 28 November 2011

Fix the arrow problem in OS X with the python interpreter

Install the readline package from PyPI to enable arrow and history support in python. Download the egg and install using:

easy_install readline-*.egg

For custom python installations, move the .egg to your site-packages path and add it to your python path by adding the following to your .bash_profile:


Thursday, 24 November 2011

how to fix "error trying to exec 'f951': execvp: No such file or directory"

error trying to exec 'f951': execvp: No such file or directory
error trying to exec 'cc1': execvp: No such file or directory

I was trying to compile a program today on OS X Lion using gfortran, but to my disappointment I got these errors every time. I am not really familiar with this kind of stuff, so I wasn't sure where to look at first. Even when trying to compile a simple hello_world program.

The internet wasn't very useful either. Google gave me barely anything :(

The solution

First I removed xcode, with the idea to reinstall it later:

sudo /Developer/Library/uninstall-devtools -mode=all

After that I dug into my /usr/local/lib and /usr/bin folders and removed any reference to gcc, gcov, g++, cpp and gfortran, which are all part of the gcc package.

I also removed all references to llvm-* (where * can be gcc, g++, etc). This comes with xcode, not really sure what this is used for. And finally I removed the libgcc/ folder and all libgfortran-related files in /usr/local/lib.

I rebooted for good measure.

Next I got Xcode 4 from the Appstore (for OS X 10.6 and lower, it's available on the Mac Dev Center and installed it. Again I went into my /usr/bin/ and removed the symlink xcode made to their (incomplete, it misses gfortran) gcc.

I downloaded and installed gcc-lion.tar.gz from HPC and installed using:
gunzip gcc-lion.tar.gz sudo tar -xvf gcc-bin.tar -C /

After that, everything seemed to work! There is without doubt a faster way to fix it, but after trying to fix it for a few hours, I'm glad it now works! :)

What else?

If gcc gives an error that looks something like this:

ld: symbol(s) not found for architecture x86_64 collect2:
ld returned 1 exit status,

an explanation can be found here. Basically, the lstdc++ parameter has to be given, so it uses the correct library. Alternativey, g++ or clang++ can be used directly.

Useful links:

Tuesday, 15 November 2011

Print terminal output to file (python)

I found this awesome code snippet for python that will automatically print any print anything that is posted to the terminal to a file.

class Writer:
    def __init__(self, stdout, filename): 
        self.stdout = stdout 
        self.logfile = open(filename, 'w') 

    def write(self, text): 

    def close(self): 

This class will then inherit and modify the standard sys.stdout:
writer = Writer(sys.stdout, output_filename) 
sys.stdout = writer

Saturday, 15 October 2011

Speed up OS X Lion

Speed up Mission Control

In terminal, enter the following commands to speed up the Expose and Workspaces transition delays:

defaults write expose-animation-duration -float 0.15
defaults write workspaces-edge-delay -float 0.15 
killall Dock

You can modify the 0.15 to whatever you want, but this is my preferred settings :)

Remove mouse acceleration

defaults write .GlobalPreferences -1

It should come into effect after relogging.

Remove Window delay

This will get rid of the animation when opening a new window.

defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool NO

Other useful links:


Thursday, 6 October 2011

Installing Cocos2d on Windows

Cocos2d uses Python 2.6. The official python website no longer releases an installer for 2.6.x. Therefore, to install, the easiest way is to get the installer (32 bit) from ActivePython.

Make sure to add Python 2.6 to your system environment variables. If you don't know how to do that, see my blog post here. Now, you can type python2.6 in Powershell/cmd to launch this version. I believe the path that is first in the environment variables string is called by default, so typing python for me will still launch Python 2.7

Get the latest version of cocos2d and pyglet. I have multiple versions of Python installed, so I went with the source distribution for the latter (.zip file).

Both packages are then easily installed by extracting them somewhere, browsing to the folders in Powershell/cmd (type powershell or cmd in the address bar in windows explorer) and typing:

python2.6 install

Test by opening up an instance of python and type:

import cocos

Friday, 30 September 2011

Merge Gmail accounts or import old accounts into Gmail

Since I got my master's degree, I am no longer affiliated with my university. The email address I had been using for the past 7 years -- for many of those years as my main address, until I switched to Gmail -- is therefore also expiring. I have 5 months to back everything up.

Luckily, Google makes it very easy for me to back up all my contacts and emails to my Gmail account. The following takes about 2 minutes to do:

  1. Log into your Gmail account
  2. Go to Mail settings, then Accounts and Import
  3. Then follow the Import mail and contacts wizard. 
Google will then proceed to backup everything, so prepare for some spam :)

Sunday, 4 September 2011

Code syntax highlighting on blogger

This is just a short post to test syntax highlighting for Blogger.

When looking for a better way to show code in my upcoming blogs, I came across this javascript syntax highlighter. I have it set up to only work with Python at the moment. It can be used by wrapping the code in the pre-tag:

<pre class="brush: python"> CODE GOES HERE </pre>

def co_sort(a,b):
	'''Sorts 2 lists according to the items in one.'''
	# r is needed so it works with arrays in b
	r = range(len(a))
	c = zip(a,r,b)
	c = unzip(c)
	return c[0],c[2]

It seems to need some time to load, but overall it works pretty well. Apparently, there is a problem when using the greater-than and smaller-than signs, have to be escaped as &lt; and &gt; isntead.

See here how to set it up for your blog.

How to install Numpy, Scipy and other python packages in Windows.

This is a short overview/guide on how to install Python packages in Windows, such as Numpy, which is an amazing tool for data manipulation.

For working with Numpy and Scipy, Python27 32-bit (first download link!) is required. Scipy[ and Numpy both have installers for windows and are extremely painless to install (compared to trying to install both for the first time on Mac OS X! :D)

To install packages, setuptools is required. This will install easy_install.

If you have added python to your system variables as described in my previous blog post, packages can be installed as follows. First we will install pip, as this is a newer and better package manager than 'easy_install'. In this example I will show how to install uncertainties, a great package I like to use for handling standard deviations in calculations (works with numpy too!).

cd C:\Python27\scripts
python .\ pip
python .\ install uncertainties

python .\ help
For an overview of pip commands.

I'm sure there is a better way to input those commands, but I'm not all too familiar yet with cmd/powershell and python in Windows :) However, I can confirm that this works fine!

Again, I suggest installing 'nose' to test and validate your Numpy and Scipy installations:

python .\ install nose

With nose, you can test if your numpy/scipy installation is correctly installed by opening a python terminal and typing:

import numpy
import scipy

Open Powershell from from windows explorer

To open Powershell starting with the path of the folder you are working in, hit alt-D to select the address bar and type powershell. The other way around, to open an explorer window from powershell, type ii . or explorer . (note the dots).

Similarly, to open an cmd window, shift-right click > 'Open command window here' or type 'cmd' in the address bar and to go back: explorer . (again, note the dot). ii seems to be Powershell specific.

It couldn't be easier! And who knew that this was all built into windows already!

Spdif digital out in Debian (and maybe other linux distros)

Short overview of what I did to get my sound card working properly in at least VLC and Opera (flash video), which is good enough for now. Could not get the default movie player and rhythmbox working :(

This website was key: click here

There are three things I did that are probably related, but I'm not sure what actually triggered it to work.

  1. In alsamixer ("alsamixer" in terminal), set the view to "all" (press f5) and unmute (press "m") S/PDIF
  2. In Volume control (System>Settings>Sound) enable all IEC958 or equivalent (fiddle around with the settings, you'll find it).
  3. In the Multimedia System Selector (in terminal: gstreamer-properties), set default output plugin to ALSA and put the device to digital ("ALC889" for me). Both analog and digital worked for me. If you hit test and get a super annoying beep, you know it works :D

Hope this helps!!

*Tested on Debian Squeeze 6.02

How to install Python for Windows

Installing Python 2.7 for Windows 7 is quite simple when using the installer.

Because I'm used to working with the Terminal, I wanted to have something similar in Windows, which is possible with cmd.exe and the newer Powershell. Powershell comes standard with Windows 7 and can be downloaded here for Windows XP.

In order to call python, a system environment variable has to be set:

Windows 7:

  1. Go to Control Panel > System > Advanced System Settings
  2. Environment Variables
  3. Add ;C:/python27 to the end of the "path" system variable (or whatever the path to your python.exe is)

Alternatively, cygwin is a terminal/bash port for Windows, which might be even easier to use.

Open PDF locked with the FileOpen Webpublisher DRM on OS X

If you have been unlucky enough to have to open files with the FileOpen Webpublisher DRM (ugh!), here is how to install it:

First of all, you will need Adobe Reader, as sadly, the needed plug-in isn't compable/available with Preview.

Second you will need the actual FileOpen Webpublisher] plugin for Adobe. When Adobe Reader is installed, go to your /Applications/ folder in Finder and right click on Adobe Reader and 'show package contents'. Copy the *.acroplugin files to the 'Plug-ins' folder of your Adobe Reader installation.

The next time you start Adobe reader, it should show up under Adobe Reader > Show 3rd party plugins.

It is now installed and should work correctly!

To remove the DRM in OS X, you can just print a new pdf...

OS X, Shelx and Olex2

In order to get Olex2 to play nicely with SHELX, make sure the Shelx binaries for Mac OS X are in the /usr/local/bin folder (where they should be, in my opinion and so they can be invoked from the command line) and edit the 'start' file that comes with Olex2 with your favourite text editor. Edit the following line:

export PATH=/bin:$PATH


export PATH=/usr/local/bin:$PATH

Python 2.7, numpy and scipy for OS X

Get the 2.7 python installer for OS X from here (You will need the developer tools from Apple installed!).

For easy installing of python packages, get easy_install for python 2.7. Get the correct .egg, and execute it as a shell command:

sh easy_install_something.egg

I had some trouble installing scipy using easy_install, so instead of using easy_install, a better tool is to use pip. It can be installed using

sudo easy_install-2.7 pip

if easy_install was already installed, otherwise instructions are on the website. I'm not sure if pip needs to be linked to a specific python version (I have 4 versions of python installed at the moment on my Macbook :( ), but it worked fine the first time.

Python packages can be installed using:

sudo pip install numpy
sudo pip install scipy

in that order.

pip freeze

shows the currently installed packages and

sudo pip uninstall x

uninstalls package 'x'.

This will install the most recent stable versions of numpy and scipy (numpy 1.5.1 and scipy 0.80 at the time of writing). The reason I suggest pip over easy_install is because easy_install failed to install scipy for me and pip was written to replace easy_install as it has some nice additional features like listing the currently installed packages and the ability to uninstall packages.

I also suggest installing 'nose':

sudo pip nose

With nose, you can test if your numpy/scipy installation is correctly installed by opening a python terminal and typing:

import numpy
import scipy

Another useful command you can use to check out the currently installed packages and the related documentation is to type:

pydoc2.7 -g

which opens a small python window, which will open a web browser with the requested information.

Other interesting packages as suggested on the numpy homepage:

There is a bug in matplotlib, where it isn't compatible with the newest version of numpy when loading the pylab module (matplotlib ImportError: No module named ma). If it gives this error, you can fix it by editing the following files:


and replacing

from import *


from import *

Get good color settings for Windows 7 under Boot camp

Amazing post about how to get a good color profile to use with Windows 7 under Boot camp: Neowin.
Throughout the Windows 7 beta, one thing that put me off a little bit was the poor color that I got by default, and even after using Windows to calibrate my display.

So I set out to fix it. Here's the steps I took. Keep in mind this is easier if you have the Boot Camp 3.0 drivers installed, as you'll be using the color profile generated for you by Mac OS X, and with Boot Camp 3.0 you don't need to get the profile off your other partition via a flash drive/email/upload/whatever.

  1. Open up your Macintosh HD via "Computer", and browse to /Library/ColorSync/Profiles/Displays
  2. You should see a color profile of some sort there. If you do not, try looking in /Users//Library/ColorSync/Profiles/. You may need to generate a color profile via the Mac OS X system preferences - see below
  3. Right click on this color profile and select "Install Profile". You can now close your Mac HD.
  4. Open the Control Panel, click "Adjust Screen Resolution", and click "Advanced Settings"
  5. Select the "Color Management" tab, and click the "Color Management" button that appears.
  6. Alternatively, just type "color management" into the Start menu and select it from the search pane. (thanks Danrarbc!)
  7. Click the "Advanced" tab, and click the "Change System Defaults" button.
  8. Click the "Advanced" tab in the new window that appears
  9. Ensure that the "Use Windows display calibration" checkbox is checked
  10. Select the "Devices" tab in this window again.
  11. Click the "Add" button and select the color profile you installed from your Mac partition.
  12. Click "OK"
  13. Now, select the color profile from the list.
  14. Click the "Set as default profile" button, on the bottom right.

Your display should now brighten and lose the heavy blue tinge that has plagued you for months, or even years if you used Vista.
You may not need to complete all the steps, but I did. It really does make the Windows experience on a MacBook much nicer, and the same should apply to an iMac or any Mac with an integrated display. I believe Windows can figure out external displays without problem, but don't quote me there...

Share your experiences here! I have no doubt that this guide will not work for everyone, but the guide I found didn't do everything for me (see here, thanks to whoever did that).

And happy proper color support!

If there isn't a profile there

  1. Boot into Mac OS X
  2. Open System Preferences.
  3. Open the "Displays" panel and click the "Color" tab.
  4. Click the "Calibrate" button
  5. You can actually click "next" through this wizard, the whole way through. The default settings should be selected.
  6. Once the wizard is done, your profile will be located in /Users//Library/ColorSync/Profiles/. Continue the process in Windows 7 from here.

If your color choice doesn't stick after a reboot, and you use an nVidia video card (9400M, 9600M GT, etc. etc.)

  1. Go here.
  2. Download the driver for your video card; chances are that your current driver is out of date.
  3. Install it
  4. Go to the Start Menu and start to type in 'nvidia'. You'll probably get a result that has the word 'PhysX' in it - that will get you to the nVidia control panel.
  5. On the left hand sidebar, select 'Adjust desktop color settings' (under the 'Display' header)
  6. On the screen that appears, under 'Choose how color is set', make sure 'Other applications control color settings' is the choice selected. Click OK, or exit the control panel.
  7. Now, try the guide above again.

If you use an ATI card, I can't help you as I'm on a MacBook Pro with the 9400M/9600M GT. All I can suggest is that you make sure you have the latest drivers, and are not managing your color through the ATi driver.

How to virtualize raw Linux partition inside Windows 7 with VirtualBox

To virtualize an existing linux install (Ubuntu 10.10 32-bit in my case) under Windows 7 64-bit, follow these steps:
(Most of the information here is listed in the VirtualBox help file)

  1. Install Windows 7 and Linux
  2. Install VirtualBox
  3. Open an elevated command prompt (=> rightclick command.exe and run as administrator).
  4. Browse to where virtualbox is installed (cd Program Files\Oracle\VirtualBox)
  5. Enter the following command:

    VboxManage internalcommands listpartitions -rawdisk \\.\PhysicalDrive0

    This will list the available partitions for the selected Drive. Drive0 or the first hard drive, 1 for the second hard drive etc... so you can decide which partition to take. Find the number of the partition linux is installed on.
  6. Create a .vmdk file by entering the following command:

    VboxManage internalcommands createrawvmdk -filename linux.vmdk -rawdisk \\.\PhysicalDrive0 -partitions 3

    This will create a file called linux.vmdk for disk0, partition 3, which contains information about the partition and is needed to virtualize this partition.
  7. Make sure to run VirtualBox as administrator (it won't work otherwise!!) and create a new virtual machine and load the the linux.vmdk file.
  8. Make sure to select your linux OS in Grub, especially if you have Windows as your standard OS to boot.
Some problems with this:
  • VirtualBox virtualizes the whole disk, not just the partition. With the createrawvmdk command a linux-pt.vmdk file is created, which I think contains information about the virtualized partition, but I am unable to load it in VirtualBox.
  • I am stuck at a resolution of 800x640 in Ubuntu, I have had no luck correctly installing the Guest additions.
  • Loading Windows 7 when booting the virtual disk is potentially harmful from what I read on forums.

Anyway, it works well enough for quick access to your other OS from Windows 7, but I don't find it too useful to actually work in. And the fact that it might cause serious damage to your installations, prevents me from actually using it.

For more information, see the help files in VirtualBox for 'Advanced storage configuration'. I will update this post if I find out more!

Disable mouse acceleration in OS X.

If you are like me and you hate the mouse acceleration in OS X, type this on the command line to disable it: defaults write .GlobalPreferences -1 It can be reversed by changing the -1 at the end or changing the value of the tracking speed in the OS X mouse preference pane :) You'll have to log in again for it to work. I haven't tested it in Lion, but I'm pretty sure it will work.

Get better video quality on Skype with the iSight camera

 I was a bit surprised when I wasn't testing out Skype today about the low quality of the built-in iSight camera of my MacBook. While the iSight supports 640x480 resolution, apparently Skype only uses 320x240 pixels.

However, there is a small tweak to overcome this. Using the terminal or Finder, go to:

~/Library/Application Support/Skype/yourskypeusername/

then edit the file "config.xml" with your favourite text editor and find the lines where it says:

        <device>Built-in iSight</device> 

and change that to:

        <captureheight>480 </captureheight> 
        <capturewidth>640 </capturewidth> 
        <device>Built-in iSight</device> 

to take full advantage of the resolution of your iSight camera. I have tested this on Skype 2.8 and it works great!

Source: Softonic

How to install Octave on Mac OS X Snow Leopard

I found that the easiest way to install Octave is to download the binary file from ="">here. It can just be installed by dragging and dropping, which is great. Alternatively, the instructions to install Octave from the source is available from the Octave homepage.

For snow leopard, make sure to apply the following fix to get Octave to work as mentioned here:

1 - mkoctfile
Since OSX 10.6 the Apple shipped version of gcc builds by default 64bit binaries.
As the libraries included with version 3.2.3 are 32bit, you need to apply the following patch in order for mkoctfile to work:
1.1) open the folder /Applications in the finder
1.2) right-click on and select "show package contents"
1.3) navigate to /Applications/
1.4) right-click on the file "mkoctfile" and select "Open with -> Other ... ->"
1.5) right after the line:

# along with this program; If not, see

add the lines


and save.

A binary for Gnuplot is included in the octave.dmg, which is needed to plot graphs. However, if Gnuplot is already installed on your system (see here for a short how-to) you will have to set the environment variable for the gnuplot terminal to use X11, or octave may give errors if aquaterm is not installed. To do so, just add:

export GNUTERM=X11

to your .bash_profile

If you wish to use the binary for gnuplot (version 4.2 as of writing) from the octave.dmg, look here on how to get it to work properly.

Take a quick look at files using Quick Look from the command line.

If you use OS X, you are probably familiar with quick look, a neat little tool to quickly preview files by hitting space when you have a file selected in Finder (alternatively, click the eye or use the menu). However, if you use the command line often, like me, you would like to be able to quicly view postscript, pdf or other files as well.

Add the following to your .bash_profile:

alias ql="qlmanage -p "$@" >& /dev/null"

qlmanage invokes Quick Look. It usually outputs some crap on the terminal, but if you add >& /dev/null, this is routed directly into oblivion.

So next time you want to quicly take a look at a file, you just hit ql file.x in the terminal to load it with Quick Look!

SSH and copy/install files to ipod/iphone

You need your iDevice to be jailbroken to get the OpenSSH package from Cydia and optionally SBSettings from Cydia to easily turn on/off SSH (which makes things a little bit easier and faster).

  1. Find the IP address of your iDevice in settings > wifi > blue arrow next to connected network, or alternatively, find it in SBSettings. (Make sure the pc you are connecting from and your iMachine are on the same network!)
  2. Open a terminal and browse to the folder with the files you want to transfer.
  3. Type: scp file.type root@ (or whatever the IP and/or folder is you need to copy to. /var/mobile/ is used to install applications) Answer yes if this is the first time you connect and it bugs you about fingerprints. Default password is 'alpine'.

  4. Optional:

  5. Transferred files can be installed by ssh'ing into your iDevice by opening a new terminal and typing: ssh root@ Again, answer yes if this it bugs you about fingerprints and the password will be 'alpine' again.
  6. Files can be installed as follows: cd ../var/mobile/ This will take you to the folder mentioned before.
  7. To install .deb files: dpkg -i file.deb

File permissions and rsync.

A little problem I came across when trying to set up rsync to sync my music between Windows and OS X. The following is needed to do this in order to make rsync work in Windows with Cygwin, as Windows can mess up file permissions, which causes rsync to fail, resulting in a 'permission denied' error on the client. Here is how to recursively change file permissions using cygwin:


find /path/to/base/dir -type d -exec chmod 755 {} \;


find /path/to/base/dir -type f -exec chmod 755 {} \;

rsync guide:

Gnuplot on OS X

A short guide on how to install Gnuplot on OS X!

Get the source (tar.gz) for gnuplot from here, extract and with the terminal go to the folder where Gnuplot is extracted and type:

./configure --with-readline=bsd --x-include=/usr/include/X11 --x-libraries=/usr/X11/lib
sudo make install

Download links and more detailed instructions on how to install the dependencies for jpg, png and gif output, click here!

How to take screenshots in OS X

  • Command-Shift-3: Take a screenshot of the screen, and save it as a file on the desktop
  • Command-Shift-4, then select an area: Take a screenshot of an area and save it as a file on the desktop
  • Command-Shift-4, then space, then click a window: Take a screenshot of a window and save it as a file on the desktop
  • Command-Control-Shift-3: Take a screenshot of the screen, and save it to the clipboard
  • Command-Control-Shift-4, then select an area: Take a screenshot of an area and save it to the clipboard
  • Command-Control-Shift-4, then space, then click a window: Take a screenshot of a window and save it to the clipboard


How to install gfortran and PLATON on OS X (Snow Leopard)

This is a short guide on how to install a fortran compiler and PLATON on OS X Snow Leopard (probably works as well for Lion).


Download gfortran from sourceforge download gfortran-snwleo-intel-bin.tar.gz, unzip:
gunzip gfortran-snleo-intel-bin.tar.gz

and install using

sudo tar -xvf gfortran-snleo-intel-bin.tar -C /

Further detail on how to install on other platforms/OS X versions, see here.


This requires Xcode to properly install and compile PLATON.

From here, get platon.f and xdrvr.c and compile (sometimes with errors) using:

gfortran -o platon platon.f xdrvr.c -L/usr/X11R6/lib -lX11

gfortran -c platon.f gfortran -o platon platon.o xdrvr.c -L/usr/X11R6/lib -lX11

For the validation module, check.def has to be downloaded and an environment variable has to be set in .bash_profile:

export CHECKDEF=/usr/local/lib/check.def

or wherever you chose to put it.

Friday, 2 September 2011

How to open PowerPoint files in Mac OS X

There is actually a neat little function in OS X to view PowerPoint files in OS X (Snow Leopard), so you don't need a full software suite like iWork for Keynote or Microsoft Office for Excel. Keynote was quite slow for me, because it has to convert the Power Point file.
It can be accessed by right clicking on a file and using quick look. Additionally, the file can be selected and opened in quick look by hitting space or clicking the little eye in the window. It supports both .ppt and .pptx files and loads lightning fast! See also this blog post on how to invoke quick look from the command line.