joaoventura / pybridge

Reuse Python code in native Android applications
215 stars 56 forks source link

Adding external modules #17

Closed edenbd50 closed 4 years ago

edenbd50 commented 6 years ago

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?

AmeerFaisalAdanan commented 6 years ago

Have you try installing all dependency? Because the error appears that it need numpy packages. Try installing numpy packages and update here. Wishing to provide further assistance

edenbd50 commented 6 years ago

Hey there, I have copied all the libraries and dependencies that i mentioned from the python 3.5/Lib, The error stop at the first package it sees, (which was the numpy) Have you implemented external py lib to the stdlib.zip before? Have you put it like me inside site-packages folder inside the zip?

JMSS-Unknown commented 6 years ago

I managed to get other packages working by converting them to bytecode and adding them to another zip file which was then added to sys.path (as stated in the readme).

Have you seen issues #8 and #14 where previous people have wanted to add numpy support? According to the issues, adding numpy is not as straightforward.

edenbd50 commented 6 years ago

Hey JMSS-Unonown, I have tried to convert the packages to bytecodes but it failed.. so I figured that might another way.. Could you explain how you managed to convert and put the other packages ?

JMSS-Unknown commented 6 years ago

Download the following files https://github.com/flatangle/flatlib/blob/master/scripts/build.py https://github.com/flatangle/flatlib/blob/master/scripts/utils.py

Make two folders, one which contained the scripts from above and another containing the packages you want to convert to bytecode (this folder must be named "pkg"), like so:

├───pkg
│   ├───package 1
│   └───package 2
└───scripts
        build.py
        utils.py

Then open powershell in the scripts folder and run build.py. Hopefully a new folder called build will be created one level up with a zip containing the bytecode.

Although I do not think this will work with numpy as stated in the issue and a recipe is needed to compile it, which can be found here: https://github.com/codelv/conda-mobile/tree/master/android-numpy

JMSS-Unknown commented 6 years ago

Seems like a prebuilt version of numpy for android can be found here https://anaconda.org/codelv/android-numpy/files

mahendrarajdhami commented 5 years ago

I managed to get other packages working by converting them to bytecode and adding them to another zip file which was then added to sys.path (as stated in the readme).

can you please tell me how can we convert them to bytecode and where to add sys.path and how?

t0june commented 5 years ago

Hello, have you solved this problem?

I have a problem here

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?

joaoventura commented 4 years ago

This project now uses the python-for-android toolchain. They seem to have lots of recipes for compiling C/C++-based modules..

https://github.com/kivy/python-for-android/tree/develop/pythonforandroid/recipes