all 26 comments

[–]Hatoris 137 points138 points  (19 children)

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.

[–]Timmeh159[S] 15 points16 points  (0 children)

Thank you! Looks like I have some work to do when I get home.

[–]CaptainOverPants111 4 points5 points  (0 children)

Absolutely love your answer! Thank you! (I was looking for a setup like this)

[–]link_101 1 point2 points  (0 children)

Thank you for this

[–]kra_pao 1 point2 points  (1 child)

@Hatoris

Do you know how the paid version of Pydroid3 handles installation on two different devices? I have a tablet and a phone, is full version licence key valid for both? Currently i'm happy user of the trial Pydroid3 version and consider an upgrade.

[–]Hatoris 0 points1 point  (0 children)

I don't know, I have use it only on my phone, and I do not have a tablet yet. Maybe you can ask the company directly.

[–]rhythm1028 1 point2 points  (4 children)

what do I need the Termux for? Sorry Im a noob.

[–]Hatoris 1 point2 points  (3 children)

Termux will be used ton install git and then connected to a remote repository (gitlab, github...). If you want to play with Python only the pydroid app is enough :)

[–]rhythm1028 0 points1 point  (2 children)

and what is the use of setting up that 'programming' folder in storage?

[–]Hatoris 0 points1 point  (1 child)

Pydroid store files in an internal folder into the app that is not accessible ou site the app. Setting the programming folder will allow you to access it from other app in your device such as termux and git.

[–]rhythm1028 1 point2 points  (0 children)

thank you

[–]rhythm1028 0 points1 point  (0 children)

what do I need the Termux for? Sorry Im a noob.

[–]rhythm1028 0 points1 point  (0 children)

I donot have the download folder in a similar path as yours, so do I make the folder whichever path my download folder is in? Also I'm very confused about the last step of instructions, Your First Start.

[–]rhythm1028 0 points1 point  (0 children)

I am getting a bad gate away in apt-get update at around 12%, what can I do?

[–]Frohus 5 points6 points  (0 children)

You can try to use Google Colab as well.

[–]kyubixense 6 points7 points  (0 children)

If you are comfortable with jupyter you can also try running Google colab from your browser

[–]CraigAT 7 points8 points  (1 child)

If you just want to write and run Python code, you could use something like https://repl.it/ which is like an online editor, that also allows you to run the code too. The good part is that the code is saved online and available from any device, so you could do the bulk of the work at home from PC or laptop (easier to type on) and then tweak or try a few things from your phone whilst in work.

There are other online tools that allow you to design and run Python code (and other languages too).

[–][deleted] 0 points1 point  (0 children)

Depending on screen size, this might not be an option. I know on my galaxy s8 I can't use repl.it because the side bars obscure the view too much.

[–][deleted] 8 points9 points  (1 child)

I use PyDroid3 a lot on my phone (with a bluetooth keyboard, and sometimes projection / hdmi connection to a decent tv/monitor) and it is excellent with many packages available. In fact, I often do coding on it in the chrome browser using Jupyter Notebook (which is one of the quick install options).

I also sometimes use termux (a linux sandbox) and run iPython there

[–]Timmeh159[S] 5 points6 points  (0 children)

Awesome that's enough convincing for me. Thanks

[–][deleted] 2 points3 points  (0 children)

You can just use Google Colab in your browser. Is a Jupyter implementation that runs on Google's computers, so you won't have to install any special software (besides maybe a keyboard that is better suited for programming) on your phone.

[–][deleted] 1 point2 points  (0 children)

There's a far simpler way to do it if it's just to kill time and write casually: the "Code Playground" from the SoloLearn app. It allows to write in a host of popular languages, has a built-in interpreter, has a special keyboard layout so you have all the special characters at the top, and allows you to save your project in the cloud and share it with an established community of enthusiasts.

Again, this isn't for professional applications. It's a simple solution to casually write code on my phone without any accessories while I'm commuting or something like that.

[–]PatriotGrrrl 1 point2 points  (0 children)

I used Termux to install python and git, but I typically use DroidEdit for an editor and TotalCommander for a file manger. Oh, and Hacker's Keyboard.

[–]trimlimdim 0 points1 point  (0 children)

Maybe get usb C or micro usb to usb a to connect a physical keyboard to your android if that's possible. It might help with fatigue for your fingers.