Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
DensonAbraham opened this issue Aug 8, 2023 · 1 comment

Comments

@DensonAbraham
Copy link

DensonAbraham commented Aug 8, 2023

Apologies if the issue is not well constructed, it's my first issue.

Chaquopy version

14.0.2

Relevant parts of your build.gradle file

    python {
        pyc {
            src false
        }
        buildPython "\"C:\\ProgramData\\anaconda3\\python.exe\""
        version "3.10"
        pip {
            install "opencv-contrib-python-headless"
            install "numpy"
            install "python-libraries\\onnxruntime-1.14.0-cp310-cp310-manylinux_2_27_x86_64.whl"
            install "python-libraries\\numba-0.57.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl"
            install "python-libraries\\llvmlite-0.40.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"
            install "python-libraries\\charset_normalizer-2.1.1-py3-none-any.whl"
            install "python-libraries\\safetensors-0.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"
            install "python-libraries\\psutil-5.9.5-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl"
            install "python-libraries\\scikit_image-0.21.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"
            install "python-libraries\\scikit_learn-1.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"
            install "python-libraries\\scipy-1.11.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"
            install "python-libraries\\pyaml-23.7.0-py3-none-any.whl"
            install "python-libraries\\torch-2.0.1-cp311-cp311-manylinux1_x86_64.whl"
            install "python-libraries\\rembg-2.0.50-py3-none-any.whl"
       
        }
    }


}

Describe your issue:

I am getting a opencv error when I am trying to run the app. I am trying to build a tensorflow-based fault detection system on android. So the build is successful however it crashes before the app is run. I am putting the logs below:

logcat:

--------- beginning of main
--------- beginning of kernel
--------- beginning of system
--------- beginning of crash
2023-08-08 10:34:40.678  5267-5267  AndroidRuntime          pid-5267                             E  FATAL EXCEPTION: main
                                                                                                    Process: com.chaquo.myapplication, PID: 5267
                                                                                                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chaquo.myapplication/com.chaquo.myapplication.MainActivity}: com.chaquo.python.PyException: ModuleNotFoundError: No module named 'cv2'
                                                                                                    	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3782)
                                                                                                    	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3922)
                                                                                                    	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:205)
                                                                                                    	at android.os.Looper.loop(Looper.java:294)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8176)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
                                                                                                    Caused by: com.chaquo.python.PyException: ModuleNotFoundError: No module named 'cv2'
                                                                                                    	at <python>.java.chaquopy.import_override(import.pxi:20)
                                                                                                    	at <python>.java.chaquopy.import_override(import.pxi:60)
                                                                                                    	at <python>.predictor.<module>(predictor.py:3)
                                                                                                    	at <python>.java.chaquopy.import_override(import.pxi:60)
                                                                                                    	at <python>.inference.<module>(inference.py:2)
                                                                                                    	at <python>.importlib._bootstrap._call_with_frames_removed(<frozen importlib._bootstrap>:241)
                                                                                                    	at <python>.importlib._bootstrap_external.exec_module(<frozen importlib._bootstrap_external>:883)
                                                                                                    	at <python>.java.android.importer.exec_module(importer.py:554)
                                                                                                    	at <python>.importlib._bootstrap._load_unlocked(<frozen importlib._bootstrap>:688)
                                                                                                    	at <python>.importlib._bootstrap._find_and_load_unlocked(<frozen importlib._bootstrap>:1006)
                                                                                                    	at <python>.importlib._bootstrap._find_and_load(<frozen importlib._bootstrap>:1027)
                                                                                                    	at <python>.importlib._bootstrap._gcd_import(<frozen importlib._bootstrap>:1050)
                                                                                                    	at <python>.importlib.import_module(__init__.py:126)
                                                                                                    	at <python>.chaquopy_java.Java_com_chaquo_python_Python_getModuleNative(chaquopy_java.pyx:129)
                                                                                                    	at com.chaquo.python.Python.getModuleNative(Native Method)
                                                                                                    	at com.chaquo.python.Python.getModule(Python.java:84)
                                                                                                    	at com.chaquo.myapplication.MainActivity.onCreate(MainActivity.kt:25)
                                                                                                    	at android.app.Activity.performCreate(Activity.java:8595)
                                                                                                    	at android.app.Activity.performCreate(Activity.java:8573)
                                                                                                    	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1456)
                                                                                                    	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3764)
                                                                                                    	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3922) 
                                                                                                    	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) 
                                                                                                    	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139) 
                                                                                                    	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96) 
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443) 
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:205) 
                                                                                                    	at android.os.Looper.loop(Looper.java:294) 
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8176) 
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) 
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) 
2023-08-08 10:42:01.497  6384-6384  AndroidRuntime          pid-6384                             E  FATAL EXCEPTION: main
                                                                                                    Process: com.chaquo.myapplication, PID: 6384
                                                                                                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chaquo.myapplication/com.chaquo.myapplication.MainActivity}: com.chaquo.python.PyException: ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.
                                                                                                    	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3782)
                                                                                                    	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3922)
                                                                                                    	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:205)
                                                                                                    	at android.os.Looper.loop(Looper.java:294)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8176)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
                                                                                                    Caused by: com.chaquo.python.PyException: ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.
                                                                                                    	at <python>.cv2.load_first_config(__init__.py:109)
                                                                                                    	at <python>.cv2.bootstrap(__init__.py:111)
                                                                                                    	at <python>.cv2.<module>(__init__.py:181)
                                                                                                    	at <python>.java.chaquopy.import_override(import.pxi:60)
                                                                                                    	at <python>.predictor.<module>(predictor.py:3)
                                                                                                    	at <python>.java.chaquopy.import_override(import.pxi:60)
                                                                                                    	at <python>.inference.<module>(inference.py:2)
                                                                                                    	at <python>.importlib._bootstrap._call_with_frames_removed(<frozen importlib._bootstrap>:241)
                                                                                                    	at <python>.importlib._bootstrap_external.exec_module(<frozen importlib._bootstrap_external>:883)
                                                                                                    	at <python>.java.android.importer.exec_module(importer.py:554)
                                                                                                    	at <python>.importlib._bootstrap._load_unlocked(<frozen importlib._bootstrap>:688)
                                                                                                    	at <python>.importlib._bootstrap._find_and_load_unlocked(<frozen importlib._bootstrap>:1006)
                                                                                                    	at <python>.importlib._bootstrap._find_and_load(<frozen importlib._bootstrap>:1027)
                                                                                                    	at <python>.importlib._bootstrap._gcd_import(<frozen importlib._bootstrap>:1050)
                                                                                                    	at <python>.importlib.import_module(__init__.py:126)
                                                                                                    	at <python>.chaquopy_java.Java_com_chaquo_python_Python_getModuleNative(chaquopy_java.pyx:129)
                                                                                                    	at com.chaquo.python.Python.getModuleNative(Native Method)
                                                                                                    	at com.chaquo.python.Python.getModule(Python.java:84)
                                                                                                    	at com.chaquo.myapplication.MainActivity.onCreate(MainActivity.kt:25)
                                                                                                    	at android.app.Activity.performCreate(Activity.java:8595)
                                                                                                    	at android.app.Activity.performCreate(Activity.java:8573)
                                                                                                    	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1456)
                                                                                                    	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3764)
                                                                                                    	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3922) 
                                                                                                    	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) 
                                                                                                    	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139) 
                                                                                                    	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96) 
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443) 
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:205) 
                                                                                                    	at android.os.Looper.loop(Looper.java:294) 
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8176) 
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) 
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) 



P.S : For some of the native libraries I used .whl files instead of building them myself using chquopy build tools as the build errors associated with the libraries were not coming up by using .whl files for installation instead of using pip with pypi. Can that be cause of the error?

Thank you all for the support!

@mhsmith
Copy link
Member

mhsmith commented Aug 8, 2023

Only android and any wheels will work on Android, not manylinux wheels.

I'm not sure how your build completed, since we don't have any OpenCV builds for Python 3.10. But if you change the version to 3.8, you should be able to install all of the packages in your list except for onnxruntime (#216) and safetensors. To do this, simply list the package names, e.g. install "numba".

@mhsmith mhsmith closed this as completed Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants