Caused by: com.chaquo.python.PyException: ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation

35 views Asked by At

After integrates python in Android studio by chaquopy, Can't run python file when import opencv-python Caused by: com.chaquo.python.PyException: ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.

build.gradle file in android studio.

    python {
        version "3.11"
    }

    python {
        buildPython "C:/Python311/python.exe"
    }

    python {
        pip {
            install "numpy"
            install "opencv-python"
        }
    }

    sourceSets {
        main {
            python.srcDir "src/main/python"
        }
    }
}
MainActivity.class: 

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        if (!Python.isStarted()) {
            Python.start(AndroidPlatform(this));
        }

        val py = Python.getInstance()
        val module = py.getModule("script")

    }
}

python file: script.py

import numpy as np

import cv2

text = "ABC"

num = 55

1

There are 1 answers

2
mhsmith On

Chaquopy currently only provides OpenCV for Python 3.8, so try changing the python { version } setting.

To be notified when this changes, please subscribe to this issue.