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

gekko: PermissionError: [Errno 13] Permission denied #962

Open
jeryjs opened this issue Sep 14, 2023 · 2 comments
Open

gekko: PermissionError: [Errno 13] Permission denied #962

jeryjs opened this issue Sep 14, 2023 · 2 comments
Labels

Comments

@jeryjs
Copy link

jeryjs commented Sep 14, 2023

Chaquopy version

14.0.2

Devices or emulators where the issue happens

SM-M526B - API 33 (arm-v8a)
Android Studio Emulator - API 34 (x86_64)
Android Studio Emulator - API 29 (x86)

Relevant parts of your code

build.gradle:

defaultConfig {
        applicationId "com.jery.feedformulation6"
        minSdk 24
        targetSdk 34
        versionCode 11
        versionName "1.0"

        // Python setup
        ndk {
            abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
        }
        python {
            pip {
                install "gekko"
                install "numpy"
            }
        }
    }

MainActivity.kt:

            if (! Python.isStarted()) { Python.start(AndroidPlatform(this)); }
            val data = Optimize(obj, cp, tdn, ca, ph, per)

            val py = Python.getInstance()
            val solver = py.getModule("optimization")

            try {
                val pyobj = solver.callAttr("optimization")
                string += "\n\nRESULT: $pyobj"
            } catch (e: PyException) {
                e.printStackTrace()
                string += "\n\nERROR: $e"
                Toast.makeText(this, e.message, Toast.LENGTH_LONG).show()
            }

            string  += "\n\nDATA:${data.obj}"
            binding.tvLog.text = string

And in manifest, I've given these permissions-

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Describe your issue

I have a calculation in python using the gekko library and I need to use its result in my android app (written in kotlin).
I tested an example with matplotlib and it works just fine, but when I try getting the result for my calculation using gekko, i get the error com.chaquo.python.PyException: PermissionError: [Errno 13] Permission denied: '/data/data/com.jery.feedformulation6.debugXML/files/chaquopy/AssetFinder/requirements/gekko/bin/apm'

Stack Trace (here, optimization.py is my file with the calculation using gekko library):

10:52:35.501 System.err     W  com.chaquo.python.PyException: PermissionError: [Errno 13] Permission denied: '/data/data/com.jery.feedformulation6.debugXML/files/chaquopy/AssetFinder/requirements/gekko/bin/apm'
10:52:35.501 System.err     W  	at <python>.subprocess._execute_child(subprocess.py:1704)
10:52:35.501 System.err     W  	at <python>.subprocess.__init__(subprocess.py:858)
10:52:35.501 System.err     W  	at <python>.gekko.gekko.solve(gekko.py:2097)
10:52:35.502 System.err     W  	at <python>.optimization.optimization(optimization.py:38)
10:52:35.503 System.err     W  	at <python>.chaquopy_java.call(chaquopy_java.pyx:354)
10:52:35.503 System.err     W  	at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrowsNative(chaquopy_java.pyx:326)
10:52:35.503 System.err     W  	at com.chaquo.python.PyObject.callAttrThrowsNative(Native Method)
10:52:35.504 System.err     W  	at com.chaquo.python.PyObject.callAttrThrows(PyObject.java:232)
10:52:35.504 System.err     W  	at com.chaquo.python.PyObject.callAttr(PyObject.java:221)
10:52:35.505 System.err     W  	at com.jery.feedformulation6.ui.activities.FeedsSelection.onCreate$lambda$0(FeedsSelection.kt:81)
10:52:35.506 System.err     W  	at com.jery.feedformulation6.ui.activities.FeedsSelection.$r8$lambda$_9HgehKjBc5jWdqwGBEpBJxp6V4(Unknown Source:0)
10:52:35.506 System.err     W  	at com.jery.feedformulation6.ui.activities.FeedsSelection$$ExternalSyntheticLambda0.onClick(Unknown Source:4)
10:52:35.507 System.err     W  	at android.view.View.performClick(View.java:7659)
10:52:35.507 System.err     W  	at android.view.View.performClickInternal(View.java:7636)
10:52:35.507 System.err     W  	at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
10:52:35.508 System.err     W  	at android.view.View$PerformClick.run(View.java:30144)
10:52:35.508 System.err     W  	at android.os.Handler.handleCallback(Handler.java:958)
10:52:35.509 System.err     W  	at android.os.Handler.dispatchMessage(Handler.java:99)
10:52:35.510 System.err     W  	at android.os.Looper.loopOnce(Looper.java:205)
10:52:35.510 System.err     W  	at android.os.Looper.loop(Looper.java:294)
10:52:35.510 System.err     W  	at android.app.ActivityThread.main(ActivityThread.java:8170)
10:52:35.510 System.err     W  	at java.lang.reflect.Method.invoke(Native Method)
10:52:35.510 System.err     W  	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
10:52:35.511 System.err     W  	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
@jeryjs jeryjs changed the title PermissionError: [Errno 13] Permission denied gekko: PermissionError: [Errno 13] Permission denied Sep 14, 2023
@mhsmith
Copy link
Member

mhsmith commented Sep 14, 2023

Unfortunately I don't think there's any easy way to use this package on Android. It bundles some executables for Linux, Mac and Windows, but not for Android. And an Android executable wouldn't work anyway, because of #605.

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

@jeryjs
Copy link
Author

jeryjs commented Sep 14, 2023

I see...
I was able to get the app to finally work by setting remote=true in my .py file
image
Now it works, but just the time it takes to solve is too long rn (it takes abt 10-15 secs while remote=true but less than a second otherwise).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants