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

FileNotFoundError '/bin/sh' with subprocess.py python3crystax #691

Closed
haricot opened this issue Mar 16, 2016 · 6 comments
Closed

FileNotFoundError '/bin/sh' with subprocess.py python3crystax #691

haricot opened this issue Mar 16, 2016 · 6 comments

Comments

@haricot
Copy link

haricot commented Mar 16, 2016

the error occurs when a try use subprocess with python3crystax

I/python  (24626): Traceback (most recent call last):
I/python  (24626):   File "main.py", line 36, in <module>
I/python  (24626):     ctypes.util.find_library('SDL2')
I/python  (24626):   File "/data/data/org.hello.world/files/crystax_python/stdlib.zip/ctypes/util.py", line 239, in find_library
I/python  (24626):   File "/data/data/org.hello.world/files/crystax_python/stdlib.zip/ctypes/util.py", line 103, in _findLib_gcc
I/python  (24626):   File "/data/data/org.hello.world/files/crystax_python/stdlib.zip/os.py", line 991, in popen
I/python  (24626):   File "/data/data/org.hello.world/files/crystax_python/stdlib.zip/subprocess.py", line 950, in __init__
I/python  (24626):   File "/data/data/org.hello.world/files/crystax_python/stdlib.zip/subprocess.py", line 1540, in _execute_child
I/python  (24626): FileNotFoundError: [Errno 2] No such file or directory: '/bin/sh'
I/python  (24626): Python for android ended.

it works by modifying the file in subprocess.py stdlib.zip
/.local/share/python-for-android/dists/testproject/crystax_python/crystax_python/stdlib.zip
subprocess.py

if shell:
                args = ["/bin/sh", "-c"] + args
                if executable:
                    args[0] = executable

            if executable is None:

to

if shell:
                args = ["/system/bin/sh", "-c"] + args
                if executable:
                    args[0] = executable

            if executable is None:

it does not look simple to modify the subprocess.py variables of permanent way by passing it through a script.

@kived
Copy link
Contributor

kived commented Mar 16, 2016

This is the code in both Python 2 and Python 3, and this only happens if you pass shell=True. You can work around this by calling the shell yourself (that's all subprocess does anyway).

@haricot
Copy link
Author

haricot commented Mar 16, 2016

However , testing this "import sdl2 " I get the same error

I/python  ( 8418): Android kivy bootstrap done. __name__ is __main__
I/python  ( 8418): AND: Ran string
I/python  ( 8418): Run user program, change dir and execute entrypoint
I/python  ( 8418): main.py
I/python  ( 8418): Traceback (most recent call last):
I/python  ( 8418):   File "main.py", line 7, in <module>
I/python  ( 8418):     import sdl2
I/python  ( 8418):   File "/data/data/org.hello.world/files/crystax_python/site-packages/sdl2/__init__.py", line 2, in <module>
I/python  ( 8418):     from .dll import get_dll_file, _bind
I/python  ( 8418):   File "/data/data/org.hello.world/files/crystax_python/site-packages/sdl2/dll.py", line 111, in <module>
I/python  ( 8418):     dll = DLL("SDL2", ["SDL2", "SDL2-2.0"], os.getenv("PYSDL2_DLL_PATH"))
I/python  ( 8418):   File "/data/data/org.hello.world/files/crystax_python/site-packages/sdl2/dll.py", line 49, in __init__
I/python  ( 8418):     foundlibs = _findlib(libnames, path)
I/python  ( 8418):   File "/data/data/org.hello.world/files/crystax_python/site-packages/sdl2/dll.py", line 37, in _findlib
I/python  ( 8418):     dllfile = find_library(libname)
I/python  ( 8418):   File "/data/data/org.hello.world/files/crystax_python/stdlib.zip/ctypes/util.py", line 239, in find_library
I/python  ( 8418):   File "/data/data/org.hello.world/files/crystax_python/stdlib.zip/ctypes/util.py", line 103, in _findLib_gcc
I/python  ( 8418):   File "/data/data/org.hello.world/files/crystax_python/stdlib.zip/os.py", line 991, in popen
I/python  ( 8418):   File "/data/data/org.hello.world/files/crystax_python/stdlib.zip/subprocess.py", line 950, in __init__
I/python  ( 8418):   File "/data/data/org.hello.world/files/crystax_python/stdlib.zip/subprocess.py", line 1540, in _execute_child
I/python  ( 8418): FileNotFoundError: [Errno 2] No such file or directory: '/bin/sh'
I/python  ( 8418): Python for android ended.

@kived
Copy link
Contributor

kived commented Mar 16, 2016

I don't see how that changes my comment. If shell=True is passed, this will happen, and clearly that is what is happening here. It's just not something you can easily change in this case.

Keep in mind that not many people use pysdl2 with python-for-android. This isn't a problem with Kivy apps (unless someone uses shell=True in their own code, obviously).

Also, note that I haven't closed the issue. I'm not saying this isn't an issue, I'm providing a workaround.

@haricot
Copy link
Author

haricot commented Mar 16, 2016

Thank you for your explanations ! This helps me understand.
just for the record, I have added
environ["PYSDL2_DLL_PATH"] ="/data/data/org.hello.world/lib"
to test pysdl2 work

@haricot haricot closed this as completed Mar 20, 2016
@AndreMiras
Copy link
Member

I think this is still a valid bug, until find_library() gets patched the way it was for Python2 in order to look into the correct place on Android.
See https://github.com/kivy/python-for-android/blob/0.6.0/pythonforandroid/recipes/python2/patches/ctypes-find-library-updated.patch

@wallneradam
Copy link

There is a workaround for importing sdl2:

def _import_sdl2():
    """ Bypass find_library and import sdl2 with specified DLL path """
    import os
    from ctypes import util

    os.environ["PYSDL2_DLL_PATH"] = os.path.realpath(os.getcwd() + '/../../lib')

    orig_fl = util.find_library

    def new_fl(*_, **__):
        return None

    util.find_library = new_fl
    import sdl2
    util.find_library = orig_fl

    return sdl2


sdl2 = _import_sdl2()

It is just monkey patching find_library temporarily, so only the specified environment variable is used.

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

4 participants