How to embed python into a kotlin/java Android app? - python

I have an Android app written in kotlin that needs to call python code. I would like the app to come bundled with the necessary python binaries to execute some python scripts as well as the required python libraries, ideally managed by pip in a virtual environment.
I already have some code that will copy these files from the assets folder that is bundled into the APK when building the app, but I don't know where to find recent python binaries that can run natively on Android. I'm assuming I need something like a arm64 version of python >3.7 .
A second issue I have is that I'm developing the app on Windows, so the virtual environment and some dependencies are not cross platform. I would probably need a way to either automatically convert the windows virtualenv into a valid project structure with correct dependencies, or a way to create and manage a linux virtual environment from Windows (maybe WSL can save me here).
What is the preferred method? Are there open source Android apps that have solved similar issues?

Related

Is there a way to pack a python project with all dependencies but not as an executable, but with access to the code?

since I think the original post wasn't clear enough -
EDIT:
Is there a tool or an option to pack my python project and all of it's dependencies and sub dependencies - same as pyinstaller does, but pyinstaller generates an executable binary, and I'd like to have the ability to make changes in the code after it's distributed (e.g on a client's environment)
Original Post
I have this python project, with a lot of dependencies and sub-dependencies, that's currently distributed by building it using pipenv to create a virtual environment and getting the 3rd party libraries, and pyinstaller to generate an executable which is being used on a virtual machine with another OS (I'm packing an executable to the target's machine OS by building it on a docker with the same OS).
the thing is - I'm using some data and scripts from this virtual machine in my python project, so i can't run it locally, and whenever there's a bug, or an error, I have to make changes locally and rebuild (which takes some time) and only then move the executable to the vm in order to run it.
my goal is to have all of the code packed with the dependencies, but with the structure of my project, and not as executable, so I can make quick changes on the VM itself.
The VM may not have an external connection, so I can't just install the dependencies on the machine.
is there a tool that can help me do such a thing?
Note
Currently the python version on the VM is different than the python version the project uses. it's possible to install another version if necessary.

How to distribute python application with all dependencies

I want to distribute a python application with all its dependencies. Target machine doesn't have an outside connection so I can't pip install anything
and all packages must be included.
I'm using python 2.7 for my application and the target machine has a different python version. I would like to pack python 2.7 as part of my distribution.
Any ideas?
If you want to distribute on Windows you can use py2exe: http://www.py2exe.org/
or cross-platform http://www.pyinstaller.org/
That way you convert your whole application to a single executable file, which includes everything you need to run it.

Public python program as one file with all modules included

I am new in Python, and I wonder if I can release my program in some kind of compiled build project with all modules and librarys included, so I can run it on diffrent systems? I don't want to install opencv on every pc.
You can specify a requirements.txt file which lists the dependencies used by your program. Python pip can read this file to bundle and package your application. See the docs here: https://pip.pypa.io/en/stable/user_guide/#requirements-files.
Also, I believe that OpenCV requires some native extensions installed which are not packaged with Python. Unfortunately, you'll need to install native extensions on each new machine you use.

How to setup airflow with python for a windows development environment

At work we are completing a PoC of Airflow by AirBnB. Standard operating practice is to decouple the development (i.e. DAG creation and python scripts etc) from the runtime environment. I.e. we are not allowed to script directly on the servers (bad practice anyway).
As such, I have configured intelliJ to work with Python (works as expected) in Windows (we are not allowed to have unix workstations) but I cannot find a way to install airflow in Windows. I am new to Python with a Java development background.
As such, how do I setup a local development environment IDEA ultimate for AirBnb/Airflow (there is no documentation ?
I have it working and compiling with the following step:
The steps below are for using intelliJ Ultimate edition, download the python modules.
Download the python extension for InttelliJ Ultimate edition or PyCharm
Configure and install python 2.7 for Windows.
Add the SDK to IDEA
Configure the following proxy details in environment variables to install modules using PIP ->
HTTP_PROXY=http : // user:password#your-company-proxy.com:8080
HTTPS_PROXY=http : // user:password#your-company-proxy.com:8080
(remove spaces, not allowed to post multiple links)
Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat).
Get it from http://aka.ms/vcpython27
C:_downloads>msiexec /i VCForPython27.msi ALLUSERS=1
pip install airflow
Create a new project, configure it as a python module.
Download the GIT repository -> airflow
Configure your path correctly, also set a python home and AIRFLOW_HOME.

build my project to installer for non python enviroment(both windows and linux)

my directroty sturcture is
/src (the source code directory including images)
/src/main.py (main script)
/src/subprojectfile/ (it consist of other several project file include __init__.py)
In my project I am using google procolbuffer,pygtk and other common python package like sys,time,thread etc..
I want to build an installer for non python system where user can install my application with out any python support.
For an alternative approach you might check out PyInstaller. It doesn't produce a proper installer, but rather standalone executables without external dependencies.
For windows you can use py2exe and for Linux have a look at freeze.

Categories

Resources