Archived:Python on Symbian/01. Introduction

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.

Article Metadata
Created: hamishwillee (29 Nov 2010)
Last edited: hamishwillee (28 Jun 2013)

Original Authors: Pankaj Nathani and Bogdan Galiceanu


A brief introduction to Python

The Python programming language was created by Guido van Rossum in the early 1990's. It is a high-level scripting language that benefits from a simple and human readable syntax, a comprehensive core library, and the ability to be extended using native code. Python is a multi-paradigm language, supporting object-oriented and functional programming styles, among others, giving you the freedom to approach a problem in a variety of ways.

Python on Symbian (also known as "PySymbian" or "PySymbian") is Nokia's port of the Python language for the Symbian platform, and is the subject of this book. Python on Symbian was first released by Nokia at the end of 2004, and was contributed to the Symbian Foundation in early 2010. In the following chapters, we describe the latest version of Python on Symbian, v2.0.

Why should I use Python on Symbian?

The main reason to use Python on Symbian is that it is easy to learn, and you can do a lot with very little code. Most people can read Python code with only a few hours of study, and can start developing mobile applications not long afterwards!

Applications created in Python are indistinguishable from native C++ applications and, for most purposes offer much the same performance. Most of the important functionality that is available to native applications (for example, access to the camera, device position, sensors etc) is exposed to Python applications through simple APIs.

If you are a developer proficient in another programming language (such as Symbian C++, Java ME or others) you can also benefit by using Python for rapid application development. So little code is needed when compared to other languages, that fully functional applications can be prototyped, demonstrated and tested very quickly!

Getting started

Python applications ("scripts") are simply text files containing code written in the Python programming language and named with the file extension ".py". The scripts can be written using any text editor and can be run either from within the Python Interactive Shell application on a device or device emulator, or as standalone applications that can be installed onto a Symbian device.

This section explains how to download and install Python onto your Symbian device or emulator.

Downloading the installation files

The Python on Symbian installation files can be downloaded from the Maemo Garage. The installation package contains Python reference documentation, the Application packager for making your scripts into stand-alone applications and the SIS files to be installed to a device.

Developers using Windows need to download the following files:

  • PythonForS60 2.0.0 Setup.zip: a zip file containing Python on Symbian Windows Installer. Extract to obtain PythonForS60_2.0.0_Setup.exe.
  • Python_2.0.0_SDK_3rdEdFP2.zip: a patch for the SDK to support Python development/

Developers using Linux/Mac need to download the following:

  • PythonForS60_2.0.0.tar.gz: An all-in-one archive includes all the contents provided by the Windows installer except the GUI for the packaging tool.

Setting up your computer

Run the following setup file to install on windows, or unzip the archive to install on Mac/Linux:

  • (Windows): PythonForS60_2.0.0_Setup.exe
  • (Mac/Linux): PythonForS60_2.0.0.tar.gz

On Windows, the tools and documentation are accessible from an option on the Start menu (Start | Programs | PythonForS60 2.0.0). Mac and Linux users will need to execute files directly (that is, you need to run the Application Packager by executing ensymble_gui.py).

Python 2.5.4 for PC is needed in order to use the PySymbian Application Packager, which can be downloaded from http://www.python.org/download/releases/2.5.4/.

While it is possible to use simple editors like Windows Notepad to write Python scripts, we recommend using a more powerful and flexible text editor to take advantage of built-in Python syntax highlighting and code folding. A couple of good editors are Notepad++ and Textpad.

Note.pngNote: While you can write code in the classic Python IDLE IDE (http://docs.python.org/library/idle.html), it is not possible to run code that depends on PySymbian-specific libraries in this or any other Python IDE. Python scripts for Symbian must be run inside the Symbian platform emulator or on the target device.

Installing Python onto your Symbian device

The easiest way to test your Python application is simply to run it on a Symbian device. PySymbian v2.0.0 is compatible with any Symbian device (including Nokia S60 5th Edition phones and the earlier S60 3rd Edition devices). But, if you don't have a compatible phone, don't worry, the next section explains how you can run your scripts on the Windows-hosted Symbian emulator.

The SIS files you need are available in the \PythonForS60\PySymbianDependencies\ directory of your Python installation. Windows users can open the directory from the start menu.

Using your PC Suite software, install the following files to your Symbian device (based on Symbian platform or S60 3rd Edition):

  • Python_2.0.0.sis: the PySymbian runtime
  • PythonScriptShell_2.0.0_3_2.sis: a Python Interactive Shell application for Symbian SDKs created after S60 3rd Edition FP2

(PythonScriptShell_2.0.0_3_0.sis should be used for earlier S60 3rd Edition devices).

PC Suite software is currently available for Windows operating system only. However, Linux users can install the above sis files by copying them to the SD card and launching them by the File Manager application of the phone.

To verify the installation, you should be able to launch the code using the Python icon, usually found in Installations folder.

Note.pngNote: If you wish to use Python on a non-Nokia Symbian device, you need to obtain manufacturer signed SIS file of the Python runtime. This could be available at the respective manufacturer developer websites.

Installing Python on your Symbian Emulator (Windows only)

If you don't have a Symbian device, you can still test your PySymbian scripts by running them within the Symbian platform emulator on Windows.

You'll need to install the following files (in order):

  1. 5th Edition SDK
  2. Python_2.0.0_SDK_3rdEdFP2.zip (Python patch from the Maemo Garage)

Note that you'll first need to unzip the SDK to a temporary directory, and then run setup.exe. The installation will warn that you need to install Perl, but this is only necessary for C++ development, so you may ignore the warning. The patch will then need to be unzipped over the SDK so that it writes into the SDK's \epoc32\ directory. Accept all prompts to replace files during unzipping to allow this to happen.

On first use, the Symbian SDK may prompt you to register it, which is a straightforward process, although you will need to sign up with Nokia Developer at http://www.developer.nokia.com/ if you haven't already done so.

You can launch the emulator by clicking on epoc.exe which is stored at <SDK installation directory>/epoc32/release/winscw/udeb/epoc.exe. Navigate to the Python icon in the Installations folder in the same way as you would on a device and click on the Python icon to launch the Python Interactive Script shell.

If Python shows an error message stating that the Python Runtime or PIPS Library are not installed, you will need to download and install the Open C/C++ Plugin for your SDK, which is available from Nokia Developer.

Testing sample scripts

Python's Interactive Script Shell makes it very easy to test your scripts during development. The shell is simply an application that allows you to type in and run arbitrary Python commands, or to load and run whole script files.

Let's create a simple Python application. Write the following line in your text editor:

print "Hello Python on Symbian"

Save the file as firstscript.py. Note that the extension of the file is .py and not .txt.

That's it, you're a programmer!

Testing on a Symbian device

To test the script on the phone, we first need to transfer the script using the Nokia PC Suite (Linux users can transfer the script by copying it to the SD card). Connect to the phone and copy the script to either C:\Data\Python or E:\Data\Python.

Once the file has been successfully transferred to the Python folder, it is ready to be tested. You can start the Python shell on your device by clicking on the Python icon in the Installations folder. Select Options | Run Script, and you'll see your script listed among other pre-installed scripts. Choose your script from the list by pressing OK. Your script should now start up and you should see the text "Hello Python on Symbian".

Figure: Testing scripts on a Symbian device

Hurray! You have just successfully deployed and tested your first Python script on the phone. You can also run and test the other pre-installed scripts like ball.py and snake.py, which demonstrate the power of Python on Symbian. Have fun!

Testing on Symbian Emulator

Testing scripts on the emulator is quicker than testing scripts on the device. The advantage of testing on the emulator is that you can make quick fixes to the script and test them instantly. However, it is strongly recommended to thoroughly test scripts for usability on the target devices before releasing them as 'finished'. This is because the script may behave differently on the hardware in some rare cases.

To test firstscript.py we need to place it in <SDK installation directory>\epoc32\winscw\c\data\python. Launch the Symbian emulator, navigate to the Python icon in the Installation folder and launch the script shell. You can test the script by selecting Options | Run Script and choosing firstscript.py from the list.

Figure: Testing scripts on Symbian Emulator


This chapter provides a brief overview of Python on Symbian and explains the main reasons why you should consider using it instead of Qt, Symbian C++ or Java ME. In addition, the chapter explains how to set up your Python development environment on the PC, Mac or Linux, and explains how to get scripts running on a Symbian device and on the Windows emulator. You also get to write and test your first small program!

While you're unlikely to have run into any problems following the instructions in this chapter, there are lots of excellent resources you use if you get stuck. The Nokia Developer Python wiki category has answers to lots of common questions, and the Python discussion boards are a good place to ask new questions (we and many other fellow Python developers are happy to you).

This is just a taster of how simple things can be when developing with Python on Symbian. IF you have any cool ideas, note them down, because you should be ready to implement them as you proceed through this book.

In the next chapter we start to understand the basics elements of the Python language.

Licence icon cc-by-sa 3.0-88x31.png© 2010 Symbian Foundation Limited. Portions copyright Bogdan Galiceanu, Hamish Willee, Marcelo Barros de Almeida, Mike Jipping, Pankaj Nathani and others in wiki document history list. This document is licensed under the Creative Commons Attribution-Share Alike 2.0 license. See http://creativecommons.org/licenses/by-sa/2.0/legalcode for the full terms of the license.
Note that this content was originally hosted on the Symbian Foundation developer wiki.

This page was last modified on 28 June 2013, at 02:50.
163 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.