Coder Social home page Coder Social logo

pybridge's People

Contributors

44xtc44 avatar joaoventura avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pybridge's Issues

you say about "python-for-android/dists/.../_python_bundle"

You must also copy the standard library files in python-for-android/dists/.../_python_bundle to assets/python along with the bootstrap.py file. If you don't do this, the Python interpreter will not start and the application will stop!.

Is it like this ? I tried it and really force close when opening the application.

IMG_20220210_082017

is it because I'm using a different Arch? I'm using Arch x86

SIGSEGV

Hi,

has anyone tested it recently ?

It used to send stderr to logcat correctly, permitting us to debug an app easily, but it's not the case anymore.
If there is a problem in my Python code (improper code, exception raised), now the call terminates with this error :

I/pybridge: Initializing the Python interpreter
I/pybridge: Call into Python interpreter
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x4 in tid 9120 (.jventura.pyapp), pid 9120 (.jventura.pyapp)
Disconnected from the target VM, address: 'localhost:8601', transport: 'socket'

With no log of what went wrong.

I use Android Studio 3.1.4 (linux) and crystax-ndk-10.3.2 (but this version of crystax used to work).

Any idea ?

Regards.

Provide support for python 'requests' library

Not sure if this is the right place to post the issue, as it may be more related to the crystax ndk, but I thought I'd give it a shot and see if there is a solution or workaround!

I'm attempting to use pybridge to make HTTP post requests from python code. At first I installed the requests library into the assets/python folder, but then it was raising an ImportError as it was missing the C extension called _socket. So I copied over _socket.so from crystax-ndk/sources/python/3.5/libs/arm64-v8a/modules but then I get a seg fault when calling requests.post:

11-11 09:59:21.919 28840-28840/com.jventura.pyapp A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x8 in tid 28840 (.jventura.pyapp)

I've tracked down the error to a call made to _socket.getaddrinfo. I've tried recompiling _socket.so using socketmodule.c from the Python source code and the crystax ndk, but I still get the same error. I've also tried both armeabi-v7a and arm64-v8a architectures.

Any thoughts into how I could solve this problem? Is there a workaround that allows me to make http requests within the python code?

Thanks for your time

Update docs

In https://github.com/joaoventura/pybridge#running-the-project

You should change "Finally, open the terminal and run path/to/crystax/ndk-build" to "Finally, open the terminal, cd to app/src/main/jni, and run path/to/crystax/ndk-build"

Otherwise you get the error:

Android NDK: Could not find application project directory !    
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.    
/home/jrm/Android/Crystax/crystax-ndk-10.3.2/build/core/build-local.mk:143: *** Android NDK: Aborting    .  Stop.

Thanks!

there is an error...

I downloaded your pybridge but it dosent work...
the error is java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader ~~ " couldn't find libpybridge.so "
how to fix it?

libpybridge.so x86?

I ran the ndk-build to create libcrystax.so, libpybridge.so and libpython3.5m.so in my src/main/libs/armeiabi-v7a however when trying to run the app on a x86 emulator it cannot find libpybridge.so. I copied over the armeabi-v7a libpybridge.so to an x86 folder and then get an unexpected e_machine: 40 error presumably because it's the wrong compilation. How do I get a x86 copy of libpybridge.so and other versions?

Need to hide my python file

Thanks for the Project.

Would like to know if there is a way to hide my python logic (bootstrap.py code) so that it does not get exposed.
Have few python files which I am trying to run along with my Android native files (C/CPP) - Can you please throw some lights on this?

UnsatisfiedLinkError: No implementation found

My first foray into the Android NDK so perhaps I'm doing this wrong, but having just changed the name of the package from com.jventura to com.randompkg and then changing pybridge.c to

JNIEXPORT jint JNICALL Java_com_randompkg_pybridge_PyBridge_start
JNIEXPORT jint JNICALL Java_com_randompkg_pybridge_PyBridge_stop
JNIEXPORT jint JNICALL Java_com_randompkg_pybridge_PyBridge_call

causes me to get this stack trace:

11-13 22:03:28.172 18981-18981/com.jventura.pyapp E/art: No implementation found for int com.randompkg.pybridge.PyBridge.start(java.lang.String) (tried Java_com_randompkg_pybridge_PyBridge_start and Java_com_randompkg_pybridge_PyBridge_start__Ljava_lang_String_2)
11-13 22:03:28.173 18981-18981/com.jventura.pyapp D/AndroidRuntime: Shutting down VM
11-13 22:03:28.174 18981-18981/com.jventura.pyapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                    Process: com.jventura.pyapp, PID: 18981
                                                                    java.lang.UnsatisfiedLinkError: No implementation found for int com.randompkg.pybridge.PyBridge.start(java.lang.String) (tried Java_com_randompkg_pybridge_PyBridge_start and Java_com_randompkg_pybridge_PyBridge_start__Ljava_lang_String_2)
                                                                        at com.randompkg.pybridge.PyBridge.start(Native Method)
                                                                        at com.randompkg.pyapp.MainActivity.onCreate(MainActivity.java:29)
                                                                        at android.app.Activity.performCreate(Activity.java:6672)
                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
                                                                        at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                        at android.os.Looper.loop(Looper.java:154)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:6123)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)

PyBridge.java remains as:

package com.randompkg.pybridge;

import org.json.JSONObject;
import org.json.JSONException;

public class PyBridge {
...

Is there anything else I need to change?

libpybridge.so

can you share libpybridge.so file? i use aide and cant build ndk

Cancelling a python thread or sending a keyboard interrupt signal

Hi there,

Is it possible to retain a reference to a python thread, while it is working, so that you can call stop() on it before it finishes? Or similarly, can you send the 'Ctrl+c' keyboard interrupt to a python thread through the pybridge interface?

The reason I ask is because I am getting SIGSEGV errors when making another network request through pybridge while a network request is ongoing (the network request is being done in python using the requests module).

Cannot resolve symbol 'PyBridge'

Hi,
Im using pybridge to evaluate the use of Python in Android Java apps. I built the Python packages for x86 using the p4a command installed from pip. I then copied the binaries created in build and dists to the folder python-for-android in the root of this project. I was able to build the pybridge library using ndk-build.
The build using android-studio and running in the emulator had no errors. But the app doesnt seem to start. It starts up and crashes without any messages in logcat. I can see error messages as in below in studio editor. Please help me in bringing up the app.

image

run project

Forgive my poor understanding, I do not know how to do this step----run path / to / crystalline / ndk-build

Cannot use sqlite

Starting from your template, I made the following modifications:

Added to Android.mk:

# Include libsqlite3.so

include $(CLEAR_VARS)
LOCAL_MODULE    := libsqlite3
LOCAL_SRC_FILES := $(CRYSTAX_PATH)/sources/sqlite/3/libs/$(TARGET_ARCH_ABI)/libsqlite3.so
LOCAL_EXPORT_CFLAGS := -I $(CRYSTAX_PATH)/sources/sqlite/3/include/
include $(PREBUILT_SHARED_LIBRARY)

Running ndk-build resulted in libsqlite3.so showing up in my project.

In bootstrap.py I added some quick-and-dirty test code:

def greet(args):
    """Simple function that greets someone."""
    print(0)
    import sqlite3
    print(1)
    try:
        conn = sqlite3.connect("test.db")
        print(sqlite3.version)
    except Error as e:
        print(e)
    finally:
        conn.close()
    return 'Hello %s' % args['name']

This prints 0 to the log, but then gives

12412-12412/com.jventura.pyapp A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x4 in tid 12412 (.jventura.pyapp)

What am I missing?

Thanks for this great library, BTW!

APP_ABI := all

In the Application.mk, APP_ABI is set to armeabi-v7a x86.
Is there a reason for this? Maybe a limitation of the python interpreter?
I would like to set it to APP_ABI := all.

Python.h not find

Hi, joaoventura
When I want to embed Python in Android,I discover your blog--http://joaoventura.net/blog/2014/python-android/ .Thank for you share this bolg.It help me a lot.But,you use Eclipse to build it,I use android studio.I can build libpython.so.But when I want to run project,it can't find Python.h.I don't know how to fix it.Can you help me?

ImportError: No module named 'select'

I think the stdlib.zip is lacking some modules. Like select, _ctypes or _socket.
This is error log:

File "/data/user/0/com.jventura.pyapp/assets/python/stdlib.zip/platform.py", line 115, in
File "/data/user/0/com.jventura.pyapp/assets/python/stdlib.zip/subprocess.py", line 438, in
ImportError: No module named 'select'

How do i install packages in python ?

I want to run a Django web server on my native android device using java code. So for that, I need to install some packages using pip install, since no documentation is provided with the code example here I am curious how to install it also will pyBridge support running Django webserver?

UnsatisfiedLinkedError for libpybridge.so

Hi, I have followed all steps,
I have also created the libpybridge.so inside src/main/libs using ndk-build

But still I am facing java.lang.UnsatisfiedLinkError: dlopen failed: library "libpybridge.so" not found

At System.loadLibrary("pybridge");

Any help would be appreciated

Python 2.7 implementation

Hey, any chance you could whip up an example using Python 2.7?

I tried just changing the Android.mk file to point to CrystaX's 2.7 sources, however I get errors in the pybridge.c file when executing ndk-build

jni/pybridge.c:39:15: error: variable 'AndroidlogModule' has initializer but incomplete type
static struct PyModuleDef AndroidlogModule = {
^
I'd love to use an existing Python library in a new Android app which is why I'm looking into this, but the library is written in Python 2.7 which I have no experience with so this is all new to me! I've appreciated your blog posts and this project for showing me that it's possible so thanks so far.

How to stop python thread

Hi, I encounter some problem.

  1. how can I run multiple job simultaneous.
  2. how can I stop a running python job.

Any body help me?

Add license

Please add a license (MIT, for example). At the moment everyone has to assume that all the code is all rights reserved and can't be used.

Need help for app

Hii @joaoventura can u please publish the app apk file in this resporitory . Coz it require lot of file that I don't have .if any other person have that app made then please send a link to download it in the comment.THANKS FOR UR HELP

import module error

I have a problem

from PIL import Image

2019-09-06 09:52:02.937 10551-10551/com.jventura.pyapp I/pybridge: File "/data/user/0/com.jventura.pyapp/assets/python/stdlib.zip/PIL/Image.py", line 95, in

2019-09-06 09:52:02.937 10551-10551/com.jventura.pyapp I/pybridge: ImportError: cannot import name '_imaging'

_imaging.pyd file is in the PIL folder.

I put PIL in stdlib.zip
Can you help me?

How to install crystax-ndk in Mac?

Hello, How to install crystax-ndk in Mac? I not way to find it.

https://brewinstall.org/install-crystax-ndk-on-mac-with-brew/

Homebrew Install success.
but execute brew install crystax-ndk error:

zhangkuixun$ brew install crystax-ndk
Error: No available formula with the name "crystax-ndk"
It was migrated from homebrew/core to homebrew/cask.
You can access it again by running:
brew tap homebrew/cask
And then you can install it by running:
brew cask install crystax-ndk

Followed all the mention steps But I get "libpybridge.so" not found

java.lang.UnsatisfiedLinkError: dlopen failed: library "libpybridge.so" not found
at java.lang.Runtime.loadLibrary0(Runtime.java:1087)
at java.lang.Runtime.loadLibrary0(Runtime.java:1008)
at java.lang.System.loadLibrary(System.java:1664)
at com.jventura.pybridge.PyBridge.(PyBridge.java:50)
at com.jventura.pybridge.PyBridge.start(Native Method)
at com.jventura.pyapp.MainActivity.onCreate(MainActivity.java:34)

External Native Build Error : CMAKE error

Hi Sir.
There is a build error when cmake runs during build. It shows error at the following line of code in android.toolchain.cmake

if(NOT EXISTS "${ANDROID_NDK}/source.properties")
message(FATAL_ERROR "Missing file: ${ANDROID_NDK}/source.properties. Please use NDK r12+.")
endif()

ImportError: No module named 'select'

I have error, not found select in stdlib.zip

Initializing the Python interpreter
--------------------
--PyRun_SimpleString("import bootstrap");
Traceback (most recent call last):
File "", line 1, in
File "/data/user/0/com.jventura.pyapp/assets/python/bootstrap.py", line 13, in
import platform
File "/data/user/0/com.jventura.pyapp/assets/python/stdlib.zip/platform.py", line 115, in
File "/data/user/0/com.jventura.pyapp/assets/python/stdlib.zip/subprocess.py", line 438, in
ImportError: No module named 'select'
--------------------

File directory:
assets
--python
----bootstrap.py
----stdlib.zip

@edenbd50

No module named '_ssl'

Traceback (most recent call last):
File "", line 1, in
File "/data/user/0/com.jventura.pyapp/assets/python/bootstrap.py", line 9, in
import ssl
File "/data/user/0/com.jventura.pyapp/assets/python/stdlib.zip/ssl.py", line 98, in
ImportError: No module named '_ssl'

Adding external modules

Hey there,
My python script uses the following modules:

import imageio
from PIL import Image
import cv2
mport numpy as np
from numpy import array

I've been trying to add some external pip modules to the stdlib.zip
When I install packages through pip it goes to:

/site-packages/MODULE_NAME
So I figured it might goes the same in the stdlib.zip to add folder /site-packages

Needless to say it did not work.

Traceback (most recent call last):
File "", line 1, in
File "/data/user/0/com.jventura.pyapp/assets/python/bootstrap.py", line 14, in
from numpy import array
pybridge: ImportError: No module named 'numpy'

Bottom line, How do I add modules properly to the stdlib.zip?

How to include python .so modules (e.g. select.so) for all architectures?

Hi,
is there a way to include the $(CRYSTAX_PATH)/sources/python/3.5/libs/$(TARGET_ARCH_ABI)/modules/select.so file for all architectures?

I know I can copy the select.so to the assets/python folder - that works. But that will only include it for one architecture.

I tried it like this, in the Android.mk, but the python interpreter can't find it:

# Include select.so

include $(CLEAR_VARS)
LOCAL_MODULE    := select
LOCAL_SRC_FILES := $(CRYSTAX_PATH)/sources/python/3.5/libs/$(TARGET_ARCH_ABI)/modules/select.so
include $(PREBUILT_SHARED_LIBRARY)

Error:

com.jventura.pyapp I/pybridge: ImportError: No module named 'select'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.