【问题标题】:How to import numpy in Chaquopy python in android如何在 Android 的 Chaquopy python 中导入 numpy
【发布时间】:2020-07-05 13:21:50
【问题描述】:

我正在使用chaquopy 演示在 android 中运行 python。 (取自 GitHub https://github.com/ericdecanini/HelloChaquopy

我的 test1 函数返回 string

当我添加import numpy as np 行时,应用程序停止运行。

在我得到的 logcat 中:

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

请让我知道我缺少什么。

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 --- "

注意:当我将导入注释掉到 numpy 时,它运行正常。

【问题讨论】:

    标签: python android numpy chaquopy


    【解决方案1】:

    尝试在 app build.gradle 的 requirements 部分中添加包名称

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

    【讨论】:

      【解决方案2】:

      我找到了在 chaquopy android studio 中导入 numpy 的解决方案。 观看此视频,这将帮助您使用 chaquopy android studio 安装任何库

      https://youtu.be/BDmB3EFy0Qg

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-04-11
        • 1970-01-01
        • 2021-07-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多