PyMaemo/Quick start guide

(Preparing the N900 for Python Development)
(Choosing an editor)
Line 83: Line 83:
== Choosing an editor ==
== Choosing an editor ==
-
TODO
+
Unless you use a Maemo specific solution like PluThon, any good programmer oriented editor will be enough for development.
 +
 
 +
Here we list some options, both for Linux and Windows:
 +
 
 +
* [http://projects.gnome.org/gedit/ gedit]: the GNOME Editor has syntax highlight support for Python (Linux only)
 +
* [http://www.vim.org/ VIM] and [http://www.gnu.org/software/emacs/ Emacs]: the most popular editors, with many advanced features and versions for both Linux and Windows
 +
* [http://wiki.netbeans.org/Python NetBeans + Python plugin]: NetBeans is a multi-platform IDE, which with help of a plugin, supports development for Python
 +
 
 +
Note that any of these editors will support code completion for PyMaemo modules out of box.
== Running the Python application on the device ==
== Running the Python application on the device ==

Revision as of 14:12, 17 December 2009

Contents

Getting Started: Setting Up Python Development Environment for N900

A basic development environment for Python development for Maemo consists of:

  • A source code editor
  • Some way to transfer application files to the tablet
  • Easily run the application (without installing it)

There is also the option of using a full Python IDE for Maemo, called PluThon. See the project site for details. While PluThon is easy to use and provides a complete solution, it is not necessary for basic Python development for Maemo. If you intend to use PluThon, there is no need to follow the instructions described here, as PluThon takes care of all the necessary steps.

This article will cover:

  • Installation of necessary packages and USB connectivity setup
  • Some suggestions for Python code editors
  • How to transfer the application files to the N900
  • How to run the application

Application packaging and final deployment will not be covered.

Requirements

Before continuing, make sure you have:

Tablet requirements:

  • Some kind of connectivity to the tablet (e.g. WLAN or GPRS), so that you can install required packages.
  • The N900 USB cable, which will be used to transfer files to the tablet.

Host requirements:

  • A SSH client. For Linux, OpenSSH (through the "ssh" command) is enough. For Windows, Tera Term can be used.
  • A SCP/SFTP client. For Linux, OpenSSH (through the "scp" command) is enough. The KDE/GNOME environments also have built-in support for these protocols. For Windows, you can try WinSCP or FileZilla.

For the purposes of this tutorial, you will not need Scratchbox installed. Scratchbox would only be necessary if you are unable to test your applications on the actual tablet.

Installing required packages on N900

You will need to install two applications on the tablet:

  • OpenSSH Server
  • rootsh

OpenSSH is needed to run commands remotely on your N900. This will make testing on the device a lot easier.

rootsh allow to run commands as root on the X Terminal (using "sudo gainroot"). See http://wiki.maemo.org/Root_access for other options to enable root access.

To install these applications, follow these steps:

  1. Enable extras repository. See http://wiki.maemo.org/Extras#Using_Extras for how to do it.
  2. Install the packages listed above.
  3. The installation will ask for a new root password for SSH access. Choose a good one.
  4. Wait for installation to complete.

Enabling USB networking

USB networking allows to easily and quickly transfer files to the device and connect to it using SSH. To enable it, follow these steps (you need to repeat them every time you reboot the device):

  1. If the USB cable is plugged and in "Mass storage mode", unplug the cable and plug it again, now selecting "PC Suite Mode".
  2. On N900, open "X Terminal" and run:
rootsh ifup usb0
  1. Now you need to configure the host. This is dependent on which OS (or Linux distro) you use, see http://wiki.maemo.org/USB_networking#Host_USB_Network_Configuration for detailed instructions for various OSes and Linux distros.

From now on you can connect to the N900 using any SSH client and the following information:

Host: 192.168.2.15
Port: 22
User: root
Password: the password setup earlier

For instance, from a Linux terminal, you can connect to the tablet using this command:

ssh root@192.168.2.15

Preparing the N900 for Python Development

To enable the full power for Python development for Maemo, you must enable the "extras-devel" repository on your device. Be advised that this might be a risky operation because extras-devel contains many untested and possibly broken packages. But it also contains the latest versions of all available Python bindings for Maemo, which we are interested on.

Note that the requirement to enable the "extras-devel" repository might be removed later.

To enable extras-devel add a new catalogue to the Application Manager, as instructed in http://wiki.maemo.org/Extras-devel (did you see the big warning on that page?)

After extras-devel is enabled, you will see on Application Manager a package called "maemo-python-device-env". Installing it will also install the basic environment necessary to run most Python applications on Maemo.

Choosing an editor

Unless you use a Maemo specific solution like PluThon, any good programmer oriented editor will be enough for development.

Here we list some options, both for Linux and Windows:

  • gedit: the GNOME Editor has syntax highlight support for Python (Linux only)
  • VIM and Emacs: the most popular editors, with many advanced features and versions for both Linux and Windows
  • NetBeans + Python plugin: NetBeans is a multi-platform IDE, which with help of a plugin, supports development for Python

Note that any of these editors will support code completion for PyMaemo modules out of box.

Running the Python application on the device

Now that you have the N900 properly setup, you just need to copy the Python code to the device and run it.

The simplest way to copy files it to use a SFTP or SCP client. There are many free clients available for most OSes (we listed some examples on the "Requirements" section). On the Linux command line, you can use:

scp -pr my_application/ root@192.168.2.15:/root/my_application/

Replace "my_application/" with the path to the directory which contains your application files.

Finally, to run the application on the tablet, use (from a SSH terminal):

cd /root/my_application
python my_application.py