Skip to content

nbconvert entry_points call failed due to [Errno 13] Permission denied: '/' #755

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

Closed
SolomonJesurathinam opened this issue Nov 29, 2022 · 6 comments
Labels
Milestone

Comments

@SolomonJesurathinam
Copy link

SolomonJesurathinam commented Nov 29, 2022

Chaquopy version

13.0

Devices or emulators where the issue happens

Both Devices and Emulator

Relevant parts of your code

def process(content):
    import os,io
    from os.path import dirname, join

    content = bytes(content)
    filename = join(dirname(__file__), "filename1.ipynb")

    f = open(filename, 'wb')
    f.write(content)
    f.close()

    output = join(os.environ["HOME"])
    nbmain([filename,f"--output-dir={output}","--to=html","--template=classic"])

Describe your issue

It is failing when writing the file in output directory

Stack trace

FATAL EXCEPTION: main
Process: com.solomonj.chaquopytest, PID: 25412
com.chaquo.python.PyException: PermissionError: [Errno 13] Permission denied: '/'
	at <python>.pathlib.iterdir(pathlib.py:1122)
	at <python>.java.android.importer.find_distributions(.\java\android\importer.py:330)
	at <python>.importlib_metadata._itertools.unique_everseen(_itertools.py:15)
	at <python>.importlib_metadata.<genexpr>(__init__.py:853)
	at <python>.importlib_metadata.entry_points(__init__.py:856)
	at <python>.nbconvert.exporters.base.get_exporter(base.py:104)
	at <python>.nbconvert.nbconvertapp.convert_notebooks(nbconvertapp.py:594)
	at <python>.nbconvert.nbconvertapp.start(nbconvertapp.py:426)
	at <python>.traitlets.config.application.launch_instance(application.py:982)
	at <python>.jupyter_core.application.launch_instance(application.py:276)
	at <python>.test.process(test.py:20)
	at <python>.chaquopy_java.call(chaquopy_java.pyx:379)
	at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrowsNative(chaquopy_java.pyx:351)
	at com.chaquo.python.PyObject.callAttrThrowsNative(Native Method)
	at com.chaquo.python.PyObject.callAttrThrows(PyObject.java:232)
	at com.chaquo.python.PyObject.callAttr(PyObject.java:221)
	at com.solomonj.chaquopytest.MainActivity$2.onActivityResult(MainActivity.java:81)
	at com.solomonj.chaquopytest.MainActivity$2.onActivityResult(MainActivity.java:59)
	at androidx.activity.result.ActivityResultRegistry$1.onStateChanged(ActivityResultRegistry.java:149)
	at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:360)
	at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:271)
	at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:313)
	at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:151)
	at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:134)
	at androidx.lifecycle.ReportFragment.dispatch(ReportFragment.java:68)
	at androidx.lifecycle.ReportFragment$LifecycleCallbacks.onActivityPostStarted(ReportFragment.java:187)
	at android.app.Activity.dispatchActivityPostStarted(Activity.java:1279)
	at android.app.Activity.performStart(Activity.java:7968)
	at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3332)
	at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
	at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2044)
	at android.os.Handler.dispatchMessage(Handler.java:107)
	at android.os.Looper.loop(Looper.java:224)
	at android.app.ActivityThread.main(ActivityThread.java:7560)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
@mhsmith
Copy link
Member

mhsmith commented Nov 30, 2022

Please post the python section from your build.gradle file, along with any requirements files it refers to.

@mhsmith
Copy link
Member

mhsmith commented Nov 30, 2022

And please show how nbmain was initialized, as that doesn't seem to be a public API.

@mhsmith mhsmith changed the title Unable to write files due to [Errno 13] Permission denied: '/' nbconvert entry_points call failed due to [Errno 13] Permission denied: '/' Nov 30, 2022
@SolomonJesurathinam
Copy link
Author

SolomonJesurathinam commented Nov 30, 2022

Build Gradle file

ndk {
            abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
        }
        python {
            version "3.8"
            pip{
                install "-r", "requirements.txt"
            }
        }

requirements

asttokens==2.1.0
attrs==22.1.0
backcall==0.2.0
beautifulsoup4==4.11.1
bleach==5.0.1
colorama==0.4.6
decorator==5.1.1
defusedxml==0.7.1
entrypoints==0.4
executing==1.2.0
fastjsonschema==2.16.2
ipython==8.6.0
jedi==0.18.2
Jinja2==3.1.2
jsonschema==4.17.1
jupyter_client==7.2.0
jupyter_core==5.0.0
jupyterlab-pygments==0.2.2
MarkupSafe==2.1.1
matplotlib-inline==0.1.6
mistune==2.0.4
nbclient==0.7.0
nbconvert==7.2.5
nbformat==5.7.0
nest-asyncio==1.5.6
packaging==21.3
pandocfilters==1.5.0
parso==0.8.3
pickleshare==0.7.5
platformdirs==2.5.4
prompt-toolkit==3.0.33
pure-eval==0.2.2
Pygments==2.13.0
pyparsing==3.0.9
pyrsistent==0.19.2
python-dateutil==2.8.2
pyzmq==18.1.1
six==1.16.0
soupsieve==2.3.2.post1
stack-data==0.6.1
tinycss2==1.2.1
tornado==6.2
traitlets==5.5.0
wcwidth==0.2.5
webencodings==0.5.1

nbmain was initialized from nbconvert

import nbconvert.nbconvertapp
from nbconvert.nbconvertapp import main as nbmain

@mhsmith
Copy link
Member

mhsmith commented Dec 3, 2022

For some reason, nbconvert unconditionally adds the working directory to the start of sys.path. But the default working directory on Android is the root directory, which is unreadable.

We'll make Chaquopy handle this situation better in the next version. Meanwhile, you can work around it by running the following before importing nbconvert:

import os
os.chdir(os.environ["HOME"])

@mhsmith mhsmith added the bug label Dec 3, 2022
@mhsmith mhsmith added this to the 13.1 milestone Dec 3, 2022
@mhsmith
Copy link
Member

mhsmith commented Dec 3, 2022

Notes for next version: find_distributions should be able to deal with this by simply skipping over any unreadable directories. os.access(R_OK | X_OK) will probably not work, because the directory is made unreadable using SELinux, not normal permissions, so we'll just have to try reading it and catch the exception.

Since this method is contained in a meta-path finder, it should be the only part of our import system which ever sees paths outside of the AssetFinder directory. Having / at the start of sys.path doesn't seem to impede normal imports, but we should add a test for that as well.

@mhsmith
Copy link
Member

mhsmith commented Jan 29, 2023

This issue was fixed in Chaquopy 14.0.2. To upgrade, edit your app's top-level build.gradle file and change the version number of com.chaquo.python.

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

No branches or pull requests

2 participants