How to import numpy in Chaquopy python in android

Viewed 2398

I am using the chaquopy demo for running python in android. (Taken from GitHub https://github.com/ericdecanini/HelloChaquopy)

My test1 function returns string.

When I added the import numpy as np line the application stopped running.

In the logcat i get:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ericdecanini.chaquopytesttwo/com.ericdecanini.chaquopytesttwo.MainActivity}: com.chaquo.python.PyException: ModuleNotFoundError: No module named 'numpy'`

Please let me know what I am missing.

import numpy as np
import time
import math

def test1():
    x = math.sin(3.14159/2.0)
    str1 = "%.2f" % x
    str2 = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())

    return " --- OK --" + str1 + "\n --- " +str2 + "\n --- "

Note: when I commented out the import to numpy it run OK.

2 Answers

Try adding package name as mentioned here in requirements section in app build.gradle

defaultConfig {
    python {
        pip {
            install "numpy"
        }
    }
}

I find solution to import numpy in chaquopy android studio. Watch this video this will helps you to install any library with chaquopy android studio

https://youtu.be/BDmB3EFy0Qg

Related