CherryPy installation on Android

本文详细介绍如何在未获取root权限的Android设备上使用BusyBox、SL4A及Python 2.6.7安装并运行CherryPy。文章首先介绍了CherryPy的解压过程,然后说明了如何通过Python setup.py构建CherryPy,并调整cherryd脚本以兼容SL4A环境。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Background: I am using Jack Palevich’s Android Terminal (Thanks a lot to Jack!), with busybox, vim and SL4A (containing Python 2.6.7) installed. I configured Android Terminal to make the startup Android standard shell launch the busybox shell automatically. I have configured quite a few symbolic links and shell scripts to busybox so that I can use the “cp”, “rm” and “ll” easily. My phone is not rooted.


In order to install CherryPy on Android, I’ve referred to Sylvain’s blog post at http://www.defuze.org/archives/228-running-cherrypy-on-android-with-sl4a.html. Based on this, I began my journey.


The first thing is of course to extract CherryPy. If you use the busybox unzip applet and extract the files to the sdcard, it would report unable to set permissions on files. However, it’s preferrable to extract it to somewhere in the phone’s internal flash memory. Fortunately CherryPy is less than 2MB during all the installation steps, so that it won’t fill up my phone’s limited internal memory, which is only 512MB.


I extracted the CherryPy directory to /data/data/jackpal.androidterm/shared_prefs/kbox/robbie/CherryPy. This is because I’m running inside Android Terminal so it can extract to only the data directory for Android Terminal. Then, according the Sylvain’s blog, I ran “python setup.py build”. Afterwards, I got the build result in the CherryPy/build directory.


Then, I copied build/cherryd to /data/data/jackpal.androidterm/shared_prefs/kbox/bin, which is listed in my PATH environment variable. However, I found cherryd must be modified to make it run in SL4A. I ran vim on it, editing the first line in it:


#!/data/data/jackpal.androidterm/shared_prefs/kbox/bin/python


This is because previous running of setup.py references the python binary executable, which is at /data/data/com.googlecode.pythonforandroid/files/python/bin/python. This binary file doesn’t automatically load the SL4A environment (such as dynamically-linked libraries–”*.so” files). If you run the original cherryd you will see error messages from python. My /data/data/jackpal.androidterm/shared_prefs/kbox/bin/python script contains content similar to https://code.google.com/p/python-for-android/source/browse/python-build/standalone_python.sh.


The next step is to copy all the files in build/lib/cherrypy to /sdcard/com.googlecode.pythonforandroid/extras/python/cherrypy.


Then, you can try running cherryd. It should work. Use Ctrl+C to terminate it.


Then, go to cherrypy/tutorial, and run python tut01_helloworld.py. Go to your browser, open http://localhost:8080. You will see “Hello World!” in a page. It works!


After the initial test, don’t forget to delete CherryPy directory to free it out of the precious internal flash memory space (unless you don’t care or your phone has a lot of space).


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值