Introduction

The QPython community has been doing a great job bringing both, Python 2 and Python 3 to the Android platform.

While there are some limitations with the built-in tools (editor, terminal), if you require more flexibility and control for your projects, this is the guide for you.

In this article we will discuss how to configure QPython on your command line interface to run your projects anyway you need.

This guide will require that you have root access (superuser, su) on your device.

The following instructions work for both, QPython2 and QPython3. The scripts here are referencing QPython2 installation. For QPython3 just substitute the QPython2 installation path with the installation path of QPython3.

Getting QPython

Download QPython (e.g. from Google Play)
We will refer to the following installation paths.

QPython2:

/data/data/org.qpython.qpy/

QPython3:

/data/data/org.qpython.qpy3/

Configuring Executable

Step 1

In /data/data/org.qpython.qpy/files/bin copy qpython.sh to python2.sh and edit as follows:

#!/system/bin/sh
DIR=${0%/*}
. $DIR/init.sh && $DIR/python "$@"

Change permissions of python2.sh to 755.

# chmod 755 python2.sh

Step 2

Mount the system as read-write. We recommend using Ghost Commander for this task.

Create file python2 in /system/bin/
Edit python2 as follows:

#! /system/bin/sh
/data/data/org.qpython.qpy/files/bin/python2.sh "$@"

Change permissions to 755.

# chmod 755 python2

Set system to read-only again.

Step 3

Test in a terminal:

> su
# python2 --version

This should print the version without errors and return to the command line prompt:

Python 2.7.2

Fixing User Permissions

Step 1

Change folder and file permissions so that the terminal user can run python without root permissions (superuser):

> su
# chmod 755 /data/data/org.qpython.qpy
# chmod 755 /data/data/org.qpython.qpy/files
# chmod 755 /data/data/org.qpython.qpy/files/bin
# chmod 755 -R /data/data/org.qpython.qpy/files/lib
# chmod 755 -R /data/data/org.qpython.qpy/files/include

Step 2

Test in a terminal without root:

> python2 --version

This should print the version without errors and return to the command line prompt:

Python 2.7.2

Step 3

Test your own project in any folder:

screenshot_qpython_android

Et voilà! It works.

Conclusion

We have shown how to configure QPython to be usable in the command line interface, thus unleashing the power of mobile development without the shackles of the graphical user interface.