chaquo / chaquopy

Chaquopy: the Python SDK for Android
https://chaquo.com/chaquopy/
MIT License
753 stars 129 forks source link

Can't copy .pyc file in 'python' sub directory of Android app #295

Closed sayan-sen closed 4 years ago

sayan-sen commented 4 years ago

i have a .pyc file instead of .py file. Earlier i used to drag-drop or copy-paste .py files straight into python dir of my app (app/src/main/python). Now i am not able to import a pyc file instead of py file. doesnt copy at all. I need to run the pyc file isntead of py file. How to do that?

sayan-sen commented 4 years ago

When i copy and paste the file manually to the folder, it still doesnt show up in the left side project navigation panel. Hence am not able to call the script file. says com.chaquo.python.PyException: ModuleNotFoundError: No module named 'xxxx' where xxxx is the .pyc filename

mhsmith commented 4 years ago

You can't include a .pyc file in your app directly. Instead, add the .py file and let Chaquopy compile it to .pyc format during the build. This will happen automatically if you have a compatible version of Python installed.

If you want to make absolutely sure that your .py source is never exposed in the APK, add the src true setting as described here.

You can verify that this has worked by opening the APK as a ZIP, and looking in assets/chaquopy/app.zip.

sayan-sen commented 4 years ago

okay i will try what you said

sayan-sen commented 4 years ago

How do i find out which exact version of python chaquopy is using? Coz i set it as- buildPython "python3.7" but now since i added

pyc {src true} 

it shows this error: "Process 'command 'python3.7'' finished with non-zero exit value 1"

mhsmith commented 4 years ago

If you click on the "Build failed" line at the top of the build window you'll see the full error message. In this case it'll be because you need to use Python 3.8 to produce compatible bytecode.

sayan-sen commented 4 years ago

My dev system runs on Python 3.7.7. How to config android studio/Chaquopy to use python 3.8? i tried using:

  1. buildPython "/usr/local/bin/python3"
  2. buildPython "python3.8" But still it fails.
sayan-sen commented 4 years ago

ok so i installed python 3.8.3 on my mac and then used: buildPython "/usr/local/bin/python3.8" Now it builds successfully along with

pyc {
                src true
            }

Thanks.