chaquo / chaquopy

Chaquopy: the Python SDK for Android
https://chaquo.com/chaquopy/
MIT License
826 stars 131 forks source link

Cannot install openvino package #969

Open isandoqa opened 1 year ago

isandoqa commented 1 year ago

I am trying to install the openvino package https://pypi.org/project/openvino/

I tried too many openvino versions, and different python versions put It keeps showing the following error in build process:

ERROR: Could not find a version that satisfies the requirement openvino==2023.1.0 (from versions: none) ERROR: No matching distribution found for openvino==2023.1.0

Also I tried to install it from a downloaded wheel file, but get the same error.

I tried to install the same package on the laptop and it is working fine.

Here is my build project details:

plugins block in project level file:

plugins {
    id("com.android.application") version "8.1.1" apply false
    id("org.jetbrains.kotlin.android") version "1.9.0" apply false
    id("com.chaquo.python") version "14.0.2" apply false
}

plugins block in module level

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("com.chaquo.python")
}

defaule config block

defaultConfig {
        applicationId = "my app id"
        minSdk = 24
        targetSdk = 33
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

        ndk {
            abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
        }

        python {
            version "3.8"
            pip{
                options "--extra-index-url", "https://pypi.org/project"
                install "openvino"
            }
        }
    }

I did not write any code yet, the project build keeps fail due to the mentioned error

mhsmith commented 1 year ago

This package contains native components, so it would have to be built into a wheel file. If you'd like to try doing this yourself, follow the instructions here. And if you're successful, please make a pull request so we can add the package to the public repository.

If anyone else wants this package too, let us know by clicking the thumbs-up button above.

Alternatively, you could use one of the other AI packages which we already have available:

isandoqa commented 1 year ago

@mhsmith Thanks for your reply. I tried hard to build it during three days following the instructions, but I failed to do it correctly, I managed to finalize the build process successfully, but the output .whl file is not working, after using it in my android app I still get the crash with error indicates that "openvino module is not found". I think I am missing something but I do not know what it is.

mhsmith commented 1 year ago

Please create a fork of this repository, push your recipe for openvino, and post the link.

Please also post the full error message including the stack trace.

isandoqa commented 1 year ago

Here is the link of my package from the forked repo: https://github.com/isandoqa/chaquopy/tree/master/server/pypi/packages/openvino

First I tried to add it from open pypi package, but the pypi release does not include any archive file which cause a problem in build-wheel script, so I set the source to be a specific tgz file from openvino storage. When running build-wheel for this, I get an error due to the flat-layout issue. So, I had to add a setup.py file in src directory to determine the packages, then run the build-wheel again with --no-unpack option.

The build process succeed, but I believe that the openvino itself is not built within it, due to the small file size, and the error that I get when I try to use it in my android app (posted below).

Here is the content of my setup.py file that I added to src directory in recipe directory, I tried both find_packages() function and specifying the packages manually with and without samples package::

from setuptools import setup, find_packages
setup(
    name="openvino",
    version="2023.0.2",
    packages=['runtime','install_dependencies'],
)

and here is the file installation in my android build.gradle after copying the file to my app folder :


python{
    version "3.8"
    pip{
        install "openvino-2023.0.2-0-cp310-cp310-android_21_x86_64.whl"
    }
}

finally , the android project is built successfully and I can see the successful whl file building in the build log, but when the app run it crashes and I have the error:

com.chaquo.python.PyException: ModuleNotFoundError: No module named 'openvino'
at <python>.java.chaquopy.import_override(import.pxi:20)
at <python>.java.chaquopy.import_override(import.pxi:60)
at <python>.Live_Steam_Detection/face_recognition_demo.<module>
(face_recognition_demo.py:26)
at <python>.importlib._bootstrap._call_with_frames_removed
(<frozen importlib._bootstrap>:219)
at <python>.importlib._bootstrap_external.exec_module
(<frozen importlib._bootstrap_external>:843)
at <python>.java.android.importer.exec_module(importer.py:554)
at <python>.java.android.importer.exec_module(importer.py:606)
at <python>.importlib._bootstrap._load_unlocked(<frozen importlib._bootstrap>:671)
at <python>.importlib._bootstrap._find_and_load_unlocked(<frozen importlib._bootstrap>:975)
at <python>.importlib._bootstrap._find_and_load(<frozen importlib._bootstrap>:991)
at <python>.importlib._bootstrap._gcd_import(<frozen importlib._bootstrap>:1014)
at <python>.importlib.import_module(__init__.py:127)
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 sa.t2.facerecognitionsample.ui.main.MainViewModel$1.invokeSuspend(MainViewModel.kt:23)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8757)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@12b2572, Dispatchers.Main.immediate]
mhsmith commented 1 year ago

First I tried to add it from open pypi package, but the pypi release does not include any archive file which cause a problem in build-wheel script, so I set the source to be a specific tgz file from openvino storage.

Since that filename contains the word "ubuntu", I think it's probably a compiled release, not a source code package. Unless you can find source code archives somewhere else, you'll probably have to use a GitHub snapshot from here.

Secondly, from this package's Python build instructions it looks like it uses Setuptools within CMake rather than the other way round. So you'll have to provide a build.sh file which runs the necessary CMake commands to build the wheel, and then unpacks it into the prefix directory. The only Python recipes we currently have that work like this are tflite-runtime and tensorflow, except they use Make or Bazel rather than CMake.

I should warn you, it looks like this is going to be quite complicated, and I'll only be able to give you limited help.

mohdahmad242 commented 3 weeks ago

This package contains native components, so it would have to be built into a wheel file. If you'd like to try doing this yourself, follow the instructions here. And if you're successful, please make a pull request so we can add the package to the public repository.

If anyone else wants this package too, let us know by clicking the thumbs-up button above.

Alternatively, you could use one of the other AI packages which we already have available:

  • tflite-runtime
  • torch
  • tensorflow

@mhsmith Can you please upgrade the tensorflow version? The current version 2.1.0 has become redundant for many use cases. It was last updated 4 years ago. https://chaquo.com/pypi-13.1/tensorflow/

Thanks

mhsmith commented 2 weeks ago

Sorry, we won't have time to upgrade TensorFlow for the foreseeable future – see https://github.com/chaquo/chaquopy/issues/374#issuecomment-1816699326.