Porting Python modules to Maemo
In some of my earlier Python related postings someone asked if Python Imaging Library (PIL) has been ported for Maemo. It seemed like it is not, so I decided to give it a try. I’ve never before created any Python .deb packages so, this was sort of my first experiment in this area and I decided to write here how I did it. In case it would be of use to someone.
The created PIL package for Maemo can be downloaded from here. Anyone interested in porting Comix for Maemo now? One point I need to mention is that I have not tested the PIL library that I’ve created for performance and quite frankly I have no idea how to optimize it, so if anyone is interested just go ahead.
I made a test using PIL on my Nokia 770 and created a blended image of the two default wallpapers. Here’s the result. Keep on reading if you want to know how I ported the library for Maemo.
Ok, first of all you need to download the PIL source package from here. Remember that you have to use the Maemo SDK and use the ARM target when compiling. Use “sbox-config -st SDK_ARM” to change to ARM target if you aren’t using that yet. Also, you need to have the ARM version of Pymaemo installed.
Let’s get to the business now. Unpack the PIL source package…
[sbox-SDK_ARM: ~] > tar xvfz Imaging-1.1.5.tar.gz
Then go to the created Imaging-1.1.5/ directory and “compile” the PIL module, by giving the following command…
[sbox-SDK_ARM: ~/Imaging-1.1.5] > python2.4 setup.py bdist_dumb
Wait until it finishes and then move to the created dist/ directory. Unpack the packet in that directory.
[sbox-SDK_ARM: ~/Imaging-1.1.5/dist] > tar xvfz PIL-1.1.5.linux-armv5tel.tar.gz
Now, create a new directory under the Imaging-1.1.5/dist/ directory. The name of this directory will be the name of the .deb package also.
[sbox-SDK_ARM: ~/Imaging-1.1.5/dist] > mkdir pil-1.1.5.maemo_arm
Move the files that were inside the PIL-1.1.5.linux-armv5tel.tar.gz packet to the newly created directory. In this case it will only be the usr/ directory.
[sbox-SDK_ARM: ~/Imaging-1.1.5/dist] > mv usr/ pil-1.1.5.maemo-arm/
Change to that directory and create there a directory called “DEBIAN”. Go to that directory.
[sbox-SDK_ARM: ~/Imaging-1.1.5/dist] > cd pil-1.1.5.maemo-arm/ [sbox-SDK_ARM: ~/Imaging-1.1.5/dist/pil-1.1.5.maemo-arm] > mkdir DEBIAN [sbox-SDK_ARM: ~/Imaging-1.1.5/dist/pil-1.1.5.maemo-arm] > cd DEBIAN/
In this debian directory you need to create a file named “control”. The application installer will use this file to regognize the package. Use some text editor and type something like this.
Package: pil Version: 1.1.5.maemo Section: unknown Priority: optional Architecture: arm Depends: maemo, pymaemo-runtime Installed-Size: 3024 Maintainer: Your Name < your.email@address.com > Description: Python Imaging Library
Important part is the “Depends: maemo” line, since the package won’t install to the device if this is not there. For python packages it is good to also include the “pymaemo-runtime” in the depends clause, so that the installer won’t install the packages unless pymaemo is also installed. Other lines in the “control” file are quite self-explatory. PS. leave out the spaces around the email address. This silly blog wouldn’t have shown it otherwise.
Then you are basically ready to create the .deb package. Just to make sure, if the library contains executable python files, you need to check the path of the python interpreter in those files. It is the first line in the file and most likely you need to add the /var/lib/install part in front of the line to make it work on the device. Executables are usually located in usr/bin directory. Here is an example…
Change this…
#!/usr/bin/python2.4
To this..
#!/var/lib/install/usr/bin/python2.4
Now you can finally create the .deb package. To do that you have to be in the Imaging-1.1.5/dist/ folder and give this command.
[sbox-SDK_ARM: ~/Imaging-1.1.5/dist] > dpkg-deb --build pil-1.1.5.maemo-arm
Then wait a sec and your package will be ready to install on the device. That’s it!
Again, questions and comments are very welcome.

February 24th, 2006 at 8:24 pm
About porting Comix, we could use Evince for reading comic books, all we need is unrar, unzip and the latest version of shared-mime-info package (you can find it at http://webcvs.freedesktop.org/mime/shared-mime-info/) which includes the mime types for CBR and CBZ file formats.
I have generated a evince package with support for comic books (including unzip/unrar) but as we have serious restrictions using the application installer, there is no way to update the mime database automatically and when i try to open a file, Evince complains about the unrecognized mime type.
We could ask nokia guys to include the latest version of shared-mime-info in the next releases of the software image.
Best Regards.
February 24th, 2006 at 8:36 pm
Funny you mention comix, I was just thinking about it yesterday and how it’d be nice on my 770.
March 8th, 2006 at 5:33 pm
Hi all!
Has anyone made .deb-packages of their python programs yet? Is there anything different from instructions from maemo.org for normal c-code software? Maybe some differences in compiling?
We’ve started coding for 770 and its going just fine (also thanks to this forum!), but now we’ve started to plan of making installation packages of our programs to test it easier on devices.
March 8th, 2006 at 8:08 pm
Hi morical,
I’ve made .deb-packages of python software also. I had some problems getting the icons to show up in the “extras” menu, but otherwise it’s quite easy actually. The method is pretty much the same as described in this post. I might post instructions on how to make a .deb package of the uitest application that I’ve created.
March 9th, 2006 at 5:14 pm
Hello,
We’ve managed to create .deb-packages and installed them to 770. Using links with desktop and service -files we managed to create icons to extra-menu also. Now only problem is we get this error trieng to run our software from menus: “We could not read lowmem page stats.”.
Actually this error doesn’t show up in 770, program just wont start (loading… -screen stays up for a while and then shuts down), when we run application in PC inside scratchbox we get that error message and same behavior in UI. When running application in X-term in 770 everything works perfectly.
So far we’ve been creating deb-packages bit “more simple way” than in instructions, that may be the reason… our software installed in /var/lib/install/testApp.py and we linked desktop and service-files to /extra_applications and /dbus-1.0/services folders.. icon shows up in menus correctly.
March 9th, 2006 at 6:36 pm
I’ve created .deb packages also, but I’ve had somewhat different problems. I’m able to run the applications from the menu, but the “loading…” message doesn’t show up at all. The application starts, but it runs only for a certain period of time and then closes itself. I haven’t got the package.links file to create the links inside the .deb package, so I’ve simply put the .desktop file in both directories.
You wouldn’t mind emailing me or posting here the method you’ve used to create the .deb package. By combining our experienses we might get it to work.
May 11th, 2006 at 2:25 am
hello — i downloaded the PIL source and untarred it. however, when i ran ‘python2.4 setup.py bdist_dumb’, i didnt see a ‘dist’ directory created. i have a handful of files and the directories: Docs, Images, PIL, Sane, Scripts, Tk, libImaging. where should i find the PIL-1.1.5.linux-armv5tel.tar.gz file? thanks!
March 10th, 2007 at 7:49 pm
xrueymyn…
xrueymyn…
March 12th, 2007 at 9:48 am
Nice site you have!