Getting python 2.5 + gstreamer + gtk working in the Maemo Scratchbox environment
From http://www.progbox.co.uk/wordpress/?p=359
Posted on 2007-08-13 14:37:21 UTC.
Ok, so another issue which has taken me a while to get around is getting GTK and Gstreamer working properly with python2.5 in my development environment. Ok, so my program isn’t working properly yet, but that’s another issue altogether. Before, I couldn’t even get python programs running properly.
A little background, scratchbox ships with python already installed. Once inside you scratchbox environment, just run;
which python
and you’ll see the following;
[sbox-SDK_ARMEL: ~] > which python
/scratchbox/tools/bin/python
[sbox-SDK_ARMEL: ~] >
This causes us a bit of a problem as the version of python installed is 2.3. Which is not really suitable for our needs. Adding the following to your sources.list file, will enable you to install the python2.5 package, which is what we will be developing in.
deb http://repository.maemo.org/extras/ bora free
I installed python2.5 and all related dev bindings by running the following command;
apt-get install python2.5*
Now running applications as you normally would, will still fail because the SB environment is still using the old python. I don’t want to change this behavior yet, as I have seen it cause issues on other people machines. Instead, we will run our code with the python version prefixed to the command line, as demonstrated below
/usr/bin/python2.5 gst_test.py
However, this will fail if you’re trying to use gtk at all. I was using gobject for a timeout. Since gobject relies on gtk, and gtk wasn’t working I was in a bit of trouble.
Searching around on the net, I found an interesting forum post about this. It seems that the environment variable DISPLAY, needs to be pointing to a running X session, before the gtk library can be imported. If you don’t do this, you get the following;
[sbox-SDK_ARMEL: ~] > /usr/bin/python2.5 gst_test.py
Traceback (most recent call last):
File "gst_test.py", line 7, in <module>
import gtk
File "/usr/lib/python2.5/site-packages/PIL/__init__.py", line 83, in <module>
File "/usr/lib/python2.5/site-packages/PIL/__init__.py", line 70, in _init
NameError: global name '_gtk' is not defined
[sbox-SDK_ARMEL: ~] >
Which stumped me for a while. Reminding ourselves of the process we used in my previous tutorial, it’s now relatively easy to get python, gstreamer and gtk working. We first need to start Xephyr outside of the scratchbox environment, using something similar to the line below.
Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac
This will start our X server on screen 2, so we can now connect to it in our maemo environment. Back in our SB environment, start with exporting the DISPLAY variable, and then running the start up script, followed by pressing enter to get our prompt back, once the script has finished executing.
export DISPLAY=:2
af-sb-init.sh start
Now all we need to do is run our python program with the right command line. As mentioned before, the run-standalone.sh script sets up various environment variables etc, which are useful to have.
run-standalone.sh /usr/bin/python2.5 gst_test.py
Now we can get gtk apps running properly, in python. Now I just need to get gstreamer doing what I want.
Enjoy.
Thanks to the Maemo guys, this is my first post on planet Maemo too!
