Search code examples
androidshelladbqpython

How to run QPython over adb shell


I installed the QPython on my (rooted) phone. I'm having trouble, however, running the python binary over the adb shell (busybox).

I can run the python binary after setting:

export LD_LIBRARY_PATH=/vendor/lib:/system/lib:/data/data/com.hipipal.qpyplus/files

However, I cannot import any module from the standard library even setting $PYTHONPATH

export PYTHONPATH=/data/data/com.hipipal.qpyplus/files/lib/python2.7/site-packages

I found a piece of advice how to run QPython in different terminal on the community wiki ( http://wiki.qpython.org/hacker/#how-to-execute-qpythons-python-in-other-terminals ), and I dumped the enviromnent and loaded it in the adb shell, the loaded python still could not load any libraries from standard library, like random.

Loading standard libraries from QPython console works just fine. Any pointers?


Solution

  • I got python to work by following the provided link, http://wiki.qpython.org/hacker/#how-to-execute-qpythons-python-in-other-terminals, prepending all lines in the script with export, then running as root ". /sdcard/qpyenv.sh". Finally I could run "python" and "import os" and all warning at the top disappeared.

    root@trelte:/ # . /sdcard/qpyenv.sh                                            
    root@trelte:/ # python
    Python 2.7.2 (default, Oct 25 2014, 20:52:15) 
    [GCC 4.9 20140827 (prerelease)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>>