zionhigt / android-python27

Automatically exported from code.google.com/p/android-python27
0 stars 0 forks source link

myScript.py wont work #12

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.  edit hello.py and add anything, even simply: 
droid.webViewShow('http://google.com')
2. zip the new hello.py as my_python_project.zip
3. recompile with new zip and install on phone

What is the expected output? What do you see instead?
It should run just like the original hello.py, but this time open a webView and 
display google.com

What version of the product are you using? On what operating system?
the current download.  Windows and Ubuntu.  

Please provide any additional information below.
I have also tried dropping python 2.6 zip + extras, renaming globalvars, etc.. 
same problem.  the steps above (1,2,3) produce the problem on the simplest 
level.  why doesn't webViewShow() work?
Also, the script I'm wanting to compile to apk imports urllib2, mimetypes, os, 
simplejson, and many other modules.  I have it running as an apk just fine on 
platform 1.6 where you must also download the interpreter separately, but it's 
losing everyones interest because people get confused if they have to download 
the app, then the python interpreter, then back to the downloads folder to 
re-try installing the app.

Please help me.  
Thx.

Original issue reported on code.google.com by MichaelD...@gmail.com on 8 Oct 2012 at 4:55

GoogleCodeExporter commented 8 years ago
Could you attach your script + the Logcat to the issue ?

Original comment by anthony....@gmail.com on 8 Oct 2012 at 5:02

GoogleCodeExporter commented 8 years ago
Absolutely!  Sorry, my ubuntu crashed (ran out of mem, had to reinstall 
everything)

Now it runs the Template pythonAPK.apk, even when I import it as a project, and 
run it on device/emulator, works fine, flashes hello text on screen constantly 
until force quit.  then when i add my own script, save as 'hello.py', re-zip as 
'my_python_project.zip'.. install and run on device, just installs but doesn't 
run:(
I've attached the script and log cat.

Please tell me this can be fixed.. or can it only run the hello.py included (or 
any python script that doesn't have to import any modules..)

The logcat show me:
- running as android app
- clicking 'open' app twice.

Original comment by MichaelD...@gmail.com on 10 Oct 2012 at 9:52

Attachments:

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Try to run your script from the command line it will give you the errors, for 
that:

- Grab the latest version of android-python27 apk (with 
https://code.google.com/p/android-python27/source/detail?r=ef7a51447af29846f268a
d587442c1f7a585a37d) and install it

- put your script files on /sdcard

adb shell
export PYTHONHOME=/data/data/com.android.python27/files/python
export 
PYTHONPATH=/sdcard/com.android.python27/extras/python:/data/data/com.android.pyt
hon27/files/python/lib/python2.7/lib-dynload:/data/data/com.android.python27/fil
es/python/lib/python2.7
export PATH=$PYTHONHOME/bin:$PATH
export 
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/data/com.android.python27/files/python/li
b:/data/data/com.android.python27/files/python/lib/python2.7/lib-dynload
export AP_HOST=localhost
export AP_PORT=45777
am start -a com.android.python27.LAUNCH_RPC_SERVER -n 
com.android.python27/.RpcServerLauncher --ei 
com.android.python27.RPC_SERVER_PORT 45777
cd /sdcard
python seesay.py

Original comment by anthony....@gmail.com on 10 Oct 2012 at 10:14

GoogleCodeExporter commented 8 years ago
Also don't forget to add needed permisson in 
https://code.google.com/p/android-python27/source/browse/apk/AndroidManifest.xml

e.g. using droid.cameraInteractiveCapturePicture('/sdcard/jpeg.jpg') would need 
<uses-permission android:name="android.permission.CAMERA"/> or the call would 
fail.

You might also want to add try: except: blocks in your code and toast or dump 
errors to help debugging.

Original comment by anthony....@gmail.com on 10 Oct 2012 at 11:13

GoogleCodeExporter commented 8 years ago
permissions are set fine.  runs great off sdcard, here's the app I'll attach 
it.  The script's fine..  I just don't know how to get an interpreter to 
install with it.

The attached apk i use android 1.6 and up, whereas i am using sdk-11 for the 
interpreter-install-template.  could it be that the interpreter simply won't 
work if too many modules are imported?  that makes no sense, no.. or was there 
a major change since 2.6.2?  that's the python i coded seesay.py on.

Any help would be so appreciated.  I admit I'm new to eclipse.. just trying to 
learn it.  Are there any java tutorials to help one understand eclipse better?  
I'm a python guy..  so frustrating when it works fine, then trying to bundle an 
interpreter and suddenly everything's broken:(

Original comment by MichaelD...@gmail.com on 10 Oct 2012 at 7:04

Attachments:

GoogleCodeExporter commented 8 years ago
oh, the apk I attached is the 1.6 (android 2.2+) version, you can install it, 
and it prompts you to download the python2.6.2 interpreter, then runs 
perfectly:) 

sorry i'm in my own head, stayed up all night trying to figure this out.  

Surely i can get this installing an interpreter as well..?

Original comment by MichaelD...@gmail.com on 10 Oct 2012 at 7:42

GoogleCodeExporter commented 8 years ago
The problem you hit is just a matter of Manifest permission. The template added 
minimum permisson:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Your app deal with camera, sound, so you have to add those permissions in the 
AndroidManifest.xml otherwise call to native api would fail. So just add to the 
manifest after permisson above:

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.VIBRATE" />

And it will work.

Alos you might want to lower android:minSdkVersion="8" if you wan to support 
pre froyo.

Original comment by anthony....@gmail.com on 10 Oct 2012 at 7:50

GoogleCodeExporter commented 8 years ago
Try attached APK as POC.

Original comment by anthony....@gmail.com on 10 Oct 2012 at 7:57

Attachments:

GoogleCodeExporter commented 8 years ago
Amazing!  Thank you! Apparently it was working all along, but I was testing in 
on a variation of the script, that imports different modules:/

Ok, one last problem... the apk, once installed, enters a loop, whereas when 
you choose to 'not take another picture', the script reruns anyways, and runs 
over and over to infinity.

Is there an exit option?  a way to kill the script or the program?

Thank you:)

Original comment by MichaelD...@gmail.com on 11 Oct 2012 at 4:40

GoogleCodeExporter commented 8 years ago
Nevermind I got it:)  Found there were some changes that had to be made to a 
couple of the java docs, alas it's a fully independent apk!!!!!  

sl4a ROCKS!!!!! :)

Thank you so so much for your time and kind direction:)

Dave Cote 

Original comment by MichaelD...@gmail.com on 11 Oct 2012 at 9:04

GoogleCodeExporter commented 8 years ago
Ok, I spoke too soon.  The script I had been trying, that didn't work.  Well, I 
can't figure it out.

Again, it works perfectly as an apk that requests the python 2.6.2 separate 
download, so it runs fine with the separate sl4a interpreter.  I don't see why 
it wouldn't work with an 'included' interpreter.  Can you please help?  The 
logcat is exactly the same as the one I sent, verbatim, exactly the same.  Here 
is the script attached, it is intimidating, but basically it includes classes 
needed for beautifulsoup used in a specific fashion, that tends to break 
depending on the python version.  It also includes exif.py, to extract a jpeg 
thumbnail.

What is strange is that, it woks seamlessly both in the sl4a app, and as an apk 
that separately downloads the interpreter.

Can you help me bundle it with the interpreter?

Thank you for you time I really appreciate it,

Dave

Original comment by MichaelD...@gmail.com on 11 Oct 2012 at 11:46

GoogleCodeExporter commented 8 years ago
Nevermind!  I found the bug, it was beautifulsoup, can't be used for some 
reason, but i've worked around it:):)):)

Thank Youuu!!!
:)

Original comment by MichaelD...@gmail.com on 12 Oct 2012 at 7:02

GoogleCodeExporter commented 8 years ago
beautifulsoup.py is not in the Python build by default, you can add it into 
python_extras_27.zip if you need it.

Original comment by anthony....@gmail.com on 12 Oct 2012 at 7:06