Installing Anaconda on Android (aarch64) devices

๐Ÿ‡น๐Ÿ‡ผ ไธญๆ–‡็‰ˆ

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. OpenCV on Termux on Android

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

  1. Install Termux

  2. 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

  1. Log into Proot Debian as root.
1
proot-distro login debian
  1. Install dependencies of miniforge3
1
2
apt update
apt install wget python3 python3-pip vim
  1. 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
1
2
3
4
alias python=/usr/bin/python3
alias python3=/usr/bin/python3
alias pip=/usr/bin/pip
alias pip3=/usr/bin/pip
  1. Download installer from miniforge repository
1
2
wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-aarch64.sh
bash Miniforge3-Linux-aarch64.sh
  1. Press Enter. Press Q. Then type yes to confirm the license.

  2. By default miniforge will be installed to /root/miniforge3

  3. Type yes to initialize conda environment.

  4. Relogin to Proot Debian.

1
2
exit
proot-distro login debian
  1. You will see the prompt become (base)๏ผŒthat means you are in conda environments. Type conda deactivate to exit.

  2. 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:

1
conda create --name test1 python=3.6

Then activate the enviornment.

1
conda activate test1

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

  1. Create conda environment
1
2
conda create --name facedetection python=3.10.9
conda activate facedetection
  1. Install required packages
1
2
conda install -c conda-forge opencv
wget https://raw.githubusercontent.com/nagadomi/lbpcascade_animeface/master/lbpcascade_animeface.xml
  1. Create a python script
1
vim detectface.py
  1. The script will detect faces from input.jpg and create a output.jpg
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import cv2
def detectFace(filename):
    cascade = cv2.CascadeClassifier("./lbpcascade_animeface.xml")
    image = cv2.imread(filename, cv2.IMREAD_COLOR)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    gray = cv2.equalizeHist(gray)
    color = (0, 0, 255)
    faces = cascade.detectMultiScale(gray,
                                     scaleFactor = 1.1,
                                     minNeighbors = 5,
                                     minSize = (24, 24))
    for (x, y, w, h) in faces:
        cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 20)
    cv2.waitKey(0)
    cv2.imwrite("output.jpg", image)

detectFace('input.jpg')
  1. You may wonder how to move pictures into Proot Debian? Don’t forget that internal storage is mounted at /sdcard , so just type:
1
mv /sdcard/Downloads/input.jpg ~/
  1. Run the script
1
python detectface.py
  1. Move the output.jpg back to sdcard
1
mv output.jpg /sdcard/Downloads/
  1. The result.

References


Thanks for your reading. You are welcome to share articles of Ivon's Blog (ivonblog.com). Please include the original URL when reprinting or citing articles, and abide by CC BY-NC-ND 4.0 license. For commercial use, please write an e-mail to me.

written by human, not by AI

If this article is helpful to you please consider supporting me.

Leave a comment

Choose the commenting system you like.

Please login to your Github account to leave a comment. You can post codes here for discussion. For images, please upload to Imgur and copy links. Your comments would be visible to everyone on Github Discussions.

This comment system is provided by Disqus, you may see some Disqus ADs on this page. You can leave a comment anonymously but you won't receive reply notifications.