Search code examples
androidpythonchaquopy

Where To Place Chaquopy Package/Module For Files


I am attempting to reference two files in an Android application in which I am running computer vision python scripts.

Following the instructions here: https://chaquo.com/chaquopy/doc/current/android.html#resource-files

I have created in import folder which includes two files my script needs to reference. This folder is called "package1" and is in the same level as my app build gradle file.

My gradle file includes the following as the example shows:

python {
            // If Chaquopy fails to find Python on your build machine, enable and edit the
            // following line to point to a Python 3.4+ executable.
            // buildPython "C:/Python36/python.exe"

            extractPackages "package1"

...
    }

And my python script contains the following:

from os.path import dirname, join


import package1
haar_path = open(join(dirname(package1.__file__), "haar.xml"))
model_path = open(join(dirname(package1.__file__), "model.hdf5"))

However, when my apk is run on my device I recieve the following error:

"No module named package1"

I believe I may be placing my module in the wrong place, but the instructions do not give details of where to place the module files nor what format they should be referenced in, in terms of a path.

Images of file hierarchy:

Current python script file hierarchy

Within package1 folder


Solution

  • The problem occurred because there was not an

     __init__.py
    

    file in my package1 folder.

    After adding this I am receiving a different error, but this import problem has been solved.