>>> from hristog.thoughts import random
Data Science Sports Analytics Python Linux About
Natural Language Processing Fantasy Football Analysis
hristog hristogeoI came across Termux via a relatively recent mention on HackerNews. Can't remember which one it was exactly, but if you'd like to familiarise yourself with its particular design decisions, advantages, disadvantages, features, etc., you might want to head over to HackerNews and give a quick skim over the following comment threads: 1, 2, 3, 4, 5.
If you opted to do a Depth-First-Search of the above articles, then I may have already lost you as a reader already. If, however, you didn't get put off by my desperate attempts at humor, and somehow found your way back to this post, then welcome back. else # i.e., you prefer synthesized content
, keep reading :).
Once you've got Termux installed in your Android environment, you simply need a couple of straightforward steps2 to update your packages and install Python. Fortunately, Termux provides support for both versions of Python - v2 (intensely branded as "Legacy Python" in the recent history of the language) and v3.
$ apt update && apt upgrade $ termux-setup-storage $ pkg install python $ pkg install python2
Upon successful completion of the above steps, you should be able to access your Python scripts and other files from $HOME/storage
.
pip
gotcha'sAs you probably have guessed already, each Python package comes hand in hand with its accompanying pip
utility: pip
for Python v3 and pip2
for "Legacy Python".
However, observe the following check-with-a-pawn kind of situation:
$ pip --version pip 9.0.1 from /data/data/com.termux/files/usr/lib/python2.7/site-packages (python 2.7) $ pip2 --version pip 9.0.1 from /data/data/com.termux/files/usr/lib/python2.7/site-packages (python 2.7)
Cowabunga! Both pip
package managers are associated with Python 2.7 and none with
non-"Legacy Python". This may arise if you updated pip2
which then overwrites the pip
reference itself.
Fear not, young Houdini's, tomorrow never dies! There's an escape from this one, too. Simply use:
$ python -m pip install <package> $ python2 -m pip install <package>
You can subsequently turn these into aliases, and add to your $HOME/.bashrc
via:
alias pip_install=python -m pip install alias pip_install2=python2 -m pip install
Being a multi-functional terminal emulator, Termux does provide support for
traditional editors such as vi
and vim
. However, despite the built-in
key(-combination) equivalents to full-fledged keyboards (physical or otherwise), I've found the use
of CLI-based text editors3 to be a bit awkward without an external keyboard.
For the purpose of editing my Python scripts, I've found DroidEdit to do the job just well enough. Of course, Google will probably be able to provide you detailed comparisons, reviews, trade-offs and alternatives. But you wouldn't go wrong if you give DroidEdit a go, as a first attempt.
Never mind that the bottom tab, in the Google Play screenshot displayed above, is occupied by source code in another programming language (which we'll pretend we're unfamiliar with, and looks like a variety of Assembly langauge to us), which for all intents and purposes of this post can be thought of as Python :) ↩
Keep in mind you'll need to enable access and write storage permissions at the app level, for Termux. ↩
No, I do not intend to dive into a detailed dispute of the eternal Vim-vs-Emacs question. But Vim is the better one ... :) ↩