B4A Library NinjaPython - Use Python Scripts in B4A

Discussion in 'Additional libraries, classes and official updates' started by wonder, Oct 19, 2017.

  1. wonder

    wonder Expert Licensed User

    Work in progress - Work in progress - Work in progress - Work in progress - Work in progress
    np.jpg
    Work in progress - Work in progress - Work in progress - Work in progress - Work in progress

    The NinjaPython B4A library brings you the ability of utilizing the Python language inside your B4A games and apps.
    This can range from a few lines of code to entire scripts or object oriented modules, the choice is yours.

    upload_2017-10-29_22-7-17.png

    Quickstart:
    - Switch 'Compilation Mode' to Release
    - Download the library files and place them in your B4A external libraries folder.
    - Option A: Download the resource files and place them in your project's Files folder.
    - Option B: Download the test project below.
    - See the 'usage' example below.​

    Practice:

    Features:
    - CPython Interpreter 2.7.9
    - Python Standard Library
    - x86 and ARM compatible
    - Ongoing development
    Wishlist:
    - Dedicated function calls
    - Passing and returning B4A objects such as lists and maps
    - Support for 3rd party libraries
    Price (pay what you want):
    Test project:

    KanBan board:

    Library files (1.03):

    Resource files:

    Usage:
    Code:
    Dim Py As NinjaPython
    Py.Initialize
    Py.Exec(
    $"
    def SayHello(subject):
        print 'Hello, ' + subject + '!'
    "$
    )

    ...
    ...
    ...
    ...

    Py.Exec(
    "SayHello('world')"'Outputs and returns 'Hello, world!'
    Py.Finalize

    Learn:
    /SPOILER]

    Enjoy! :)
     
    Last edited: Oct 31, 2017
    Peter Simpson, tufanv, Toley and 12 others like this.
  2. Star-Dust

    Star-Dust Expert Licensed User

    Great but what does it do
     
  3. wonder

    wonder Expert Licensed User

  4. Star-Dust

    Star-Dust Expert Licensed User

    Sorry I did not explain well. I know what Phyton is, but I want to know what the code is .... is a phyton interpreter written in B4A?
     
  5. DonManfred

    DonManfred Expert Licensed User

    it is a python interpreter library. I dont think it is written in B4A but it can be used in B4A ;-)
     
    wonder likes this.
  6. Star-Dust

    Star-Dust Expert Licensed User

    That's really interesting.
    is 100% compatible or are you currently working for?
     
  7. DonManfred

    DonManfred Expert Licensed User

    First read, then ask :D
     
    wonder and Star-Dust like this.
  8. CanguroCode

    CanguroCode Active Member Licensed User

    Excelent, Congrats!
     
    wonder likes this.
  9. zhonghua

    zhonghua Member Licensed User

    Seems very promising!
     
    wonder likes this.
  10. wonder

    wonder Expert Licensed User

    The official release is almost ready, so stay tuned! ;)

    Features:
    -
    Python 2.7.9
    - ARM and x86
    - User imports
    - Python Standard Library
    - Code execution (returns stdstdout)

    Work-in-progress:
    - Library imports (eg. NumPy)
    - Direct function calls

    Price (your choice):
    - Paypal me 1 pizza or 2 beers! :D
    - Free
     
    Last edited: Oct 24, 2017
  11. wonder

    wonder Expert Licensed User

    [​IMG]
     
    thedesolatesoul likes this.
  12. CanguroCode

    CanguroCode Active Member Licensed User

    pip, wait for me.
     
  13. wonder

    wonder Expert Licensed User

    Done! :)
    First post updated.
     
    Last edited: Oct 29, 2017
  14. wonder

    wonder Expert Licensed User

    Update 1.02:
    - Install method no longer necessary, everything is handled internally

    First post updated.
     
  15. CanguroCode

    CanguroCode Active Member Licensed User

    Works just for Python Standard Library right?
     
  16. wonder

    wonder Expert Licensed User

    Yes, for now, yes.
     
    Husam likes this.
  17. Husam

    Husam Member Licensed User

    Many thanks for your work , i just test your python test then i got this error

    Code:
    *** Service (starter) Create ***
    ** 
    Service (starter) Start **
    ** 
    Activity (main) Create, isFirst = true **
    ** 
    Activity (main) Resume **
    [NinjaPython] ARM CPU detected
    Error occurred on line: 
    59 (Main)
    java.io.FileNotFoundException: python2
    .7.zip
        at android.content.res.AssetManager.openAsset(Native Method)
        at android.content.res.AssetManager.open(AssetManager.java:
    331)
        at android.content.res.AssetManager.open(AssetManager.java:
    305)
        at com.ninjadynamics.ninjapython.NinjaPython.copyAssetFile(NinjaPython.java:
    122)
        at com.ninjadynamics.ninjapython.NinjaPython.install(NinjaPython.java:
    109)
        at com.ninjadynamics.ninjapython.NinjaPython.Initialize(NinjaPython.java:
    92)
        at com.ninjadynamics.python.main._activity_resume(main.java:
    460)
        at java.lang.reflect.Method.invoke(Native Method)
        at anywheresoftware.b4a.shell.Shell.runMethod(
    Shell.java:710)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:339)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:249)
        at java.lang.reflect.Method.invoke(Native Method)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    139)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    166)
        at com.ninjadynamics.python.main.afterFirstLayout(main.java:
    108)
        at com.ninjadynamics.python.main.access$
    000(main.java:17)
        at com.ninjadynamics.python.main$WaitForLayout.run(main.java:
    80)
        at android.os.Handler.handleCallback(Handler.java:
    739)
        at android.os.Handler.dispatchMessage(Handler.java:
    95)
        at android.os.Looper.loop(Looper.java:
    148)
        at android.app.ActivityThread.main(ActivityThread.java:
    5461)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    616)
     
  18. wonder

    wonder Expert Licensed User

    Oops, it seems that I forgot to clarify on the first post, that you'll need the python zip files found in the Demo Project.
    Please copy them to your Files folder and give it another try.

    EDIT: First post updated.
     
    Last edited: Oct 31, 2017
  19. Husam

    Husam Member Licensed User

    sorry but still the same error
     
  20. wonder

    wonder Expert Licensed User

    Can you send me your B4A project?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice