Reddit Gold: “How do I run Python on android?”

Reddit Gold highlights the most useful and educational content on Reddit as found on r/AutoBestOf.

Today’s post is from u/Hatoris who answers the question: “How do I run Python on android?

Everybody told you that ” to improve your python skill you need to practice” but you do not always have your laptop with you. Hold on, here is something that can be done.

The purpose of this small tutorial is to give you the ability to install and run python and git on your Android device.

Disclaimer : I have no affiliation with any applications I will present.

Introduction

First thing first, you do not need to root your phone in order to follow this tuto. All application are free, of cource. Applications we will use are :

  • pydroid 3 a pretty good application. It’s free, prenium version give you access to autocompletion and some intelisense, it’s not the same level as pycharm but is pretty usefull.
  • Termux your Linux shell on your mobile, with this you will have access to git.
  • git, the most famous version control system for all your project

Installation

From the play store install :

From Termux

Ok, now you have it, open Termux and run the following command.

apt-get update 
apt-get upgrade

Then we can install git.

apt-get install git

Setup

It’s time to be organize and hack a little bit pydroid3.

First create a folder where all your application will site. Mine is called programming and I add it under /storage/emulated/0. This path is the same as your document and download folders.

When it’s done, copy the path in your clipboard and open pydroid3. On the right, click on folder icon and then open. Follow this path Home, accomp_files, iiec_run and finally open iiec_run.py. (Home/accomp_files/iiec_run/iiec_run.py)

Now, right under import sys add the following.

PATH ="/storage/emulated/0/programming/" #the path of your programming folder

# A tuple with all your package folders in it, at start you will have nothing, but with time it may look like mine
APPs = (
"kbase", 
"RemoveMedia", 
"pyAnalysis", 
"BioPlate", 
"appPharma", 
"pytexu", 
"Tools", 
"Dilution",
"BioPlateWeb",
"pythontex-command")

# Finally we append all path to system
for app in APPs:
    sys.path.append(PATH + app)

This little hack will alow you to import your package, those you created, not those that you will install using built in pip.

Your first start

Take your favorite web hosting service, create a package in it. Copy the link to clone it. Then go on your device and open Termux. run the command cd /emulated/storage/0/programming/, your are now in your programming folder. Clone your repo with the following git clone https://web-hosting.com/myRepo (replace the link with the one you copied). When it’s done, open your pydroid3 app, and open your cloned repo. Don’t forget to add your package in the iiec_run.py.

Happy coding

Fun fact

I written 90 % of my package BioPlate using this setup. When you have, like me, more than one hour and half of common transportation a setup like this is really cool.

Source

Leave a comment

Your email address will not be published. Required fields are marked *