change the python command used by the mobilesdk / titanium studio


I'm having some trouble configuring the Android SDK on Arch Linux (64-bit).

I'm using Titanium Studio

The problem is simple. In my box /usr/bin/python points to Python 3.2.1, and Titanium Studio needs Python 2.x.

!MESSAGE   File "/home/user/.titanium/mobilesdk/linux/1.7.2/android/", line 41
    print "Usage: %s <directory>" % os.path.basename(sys.argv[0])

Is it possible to configure the python command used by Titanium Studio? Some env variable or flag in TitaniumStudio.ini?

I've already tried a couple of things:

  • Environment variables:
    • PYTHON
  • ln -s &#x2F;usr&#x2F;bin&#x2F;python2 python in my user's bin/ directory, so that the python command for that user is Python 2.7.2.
  • Replacing every occurrence of #!&#x2F;usr&#x2F;bin&#x2F;env python with #!&#x2F;usr&#x2F;bin&#x2F;env python2 in .titanium&#x2F;mobilesdk.

The only workaround I've found so far is doing this:

sudo rm /usr/bin/python
sudo ln -s /usr/bin/python2 /usr/bin/python

But that has the slight disadvantage of breaking all other python packages / scripts in my system.

Any ideas would be appreciated, thanks.

2 Answers

  • We solved this problem with per process namespaces. We basically changed the &#x2F;usr&#x2F;bin&#x2F;python link (to point to python2) in the process running titanium rather than changing it for the whole system.

    #define _GNU_SOURCE
    #include <sched.h>
    #include <syscall.h>
    #include <unistd.h>
    int main(int argc, char *argv[]) {
        syscall(SYS_unshare, CLONE_NEWNS);
        if (argc > 1)
            return execvp(argv[1], &argv[1]);
        return execv("/bin/sh", NULL);

    And we run this in a little bash script that creates the process and sets up the filesystem, something like:

    sudo ./newns sh -c "mount -n --bind /usr/bin/python2 /usr/bin/python; su username"

    Hope this helps someone.

  • Hi there Eduardo Lopez,

    I'm pretty new to Arch Linux and a i'm a n00b with python & custom environment (to python2.7).

    Could you please explained your solution with more detail ?

    Configuring Titanium Studio correctly would make arch uber cool ::):)

    Thank you very much!