This tutorial is for those who want to install Anaconda on Android phone.
The benefit of Anaconda is that you could have multiple Python versions installed on the same device. And you can switch to different environments quickly.
An example of OpenCV program running on Termux on Android phone.
Because most Android devices are 64bit (aarch64), the Anaconda and Miniconda installers from official website will not work on Termux, therefore we have to use miniforge. The commands are almost as same as original Anaconda.
1. Setup Termux and Proot Linux
Install Termux
Though Termux does provide python packages, however the installer only works in Linux environment. Thus, we must setup a Proot Debian. You can skip installing desktop environment parts if you just want to run Python scripts.
2. Install miniforge3
- Log into Proot Debian as root.
|
|
- Install dependencies of miniforge3
|
|
- When executing python commands you would notice that it would use Python from Termux instead of Proot, so you have to execute follwoing commands to specify the path of Python installation
|
|
- Download installer from miniforge repository
|
|
Press Enter. Press Q. Then type
yes
to confirm the license.By default miniforge will be installed to
/root/miniforge3
Type
yes
to initialize conda environment.Relogin to Proot Debian.
|
|
You will see the prompt become
(base)
๏ผthat means you are in conda environments. Typeconda deactivate
to exit.If you want to disable auto activatation of conda environment, type
conda config --set auto_activate_base false
to disable it.
3. Usage of conda commands
When you are in conda environment, you can install Pyhton packages with conda install
or pip install
.
You can also create multiple virtual enviornments with different Python installed.
For example, you can create a environment with old Pyhton 3.6:
|
|
Then activate the enviornment.
|
|
Now you can install Python packages which only work on old Pyhton versions.
4. An example of OpenCV program
Let’s detect the faces of two girls from Girls’ Last Tour from the image below. We will use codes from lbpcascade_animeface
- Create conda environment
|
|
- Install required packages
|
|
- Create a python script
|
|
- The script will detect faces from
input.jpg
and create aoutput.jpg
|
|
- You may wonder how to move pictures into Proot Debian? Don’t forget that internal storage is mounted at
/sdcard
, so just type:
|
|
- Run the script
|
|
- Move the output.jpg back to sdcard
|
|
- The result.